Version 1
[yaffs-website] / web / core / modules / field_ui / src / Controller / EntityDisplayModeController.php
1 <?php
2
3 namespace Drupal\field_ui\Controller;
4
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\Core\Url;
7
8 /**
9  * Provides methods for entity display mode routes.
10  */
11 class EntityDisplayModeController extends ControllerBase {
12
13   /**
14    * Provides a list of eligible entity types for adding view modes.
15    *
16    * @return array
17    *   A list of entity types to add a view mode for.
18    */
19   public function viewModeTypeSelection() {
20     $entity_types = [];
21     foreach ($this->entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
22       if ($entity_type->get('field_ui_base_route') && $entity_type->hasViewBuilderClass()) {
23         $entity_types[$entity_type_id] = [
24           'title' => $entity_type->getLabel(),
25           'url' => Url::fromRoute('entity.entity_view_mode.add_form', ['entity_type_id' => $entity_type_id]),
26           'localized_options' => [],
27         ];
28       }
29     }
30     return [
31       '#theme' => 'admin_block_content',
32       '#content' => $entity_types,
33     ];
34   }
35
36   /**
37    * Provides a list of eligible entity types for adding form modes.
38    *
39    * @return array
40    *   A list of entity types to add a form mode for.
41    */
42   public function formModeTypeSelection() {
43     $entity_types = [];
44     foreach ($this->entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
45       if ($entity_type->get('field_ui_base_route') && $entity_type->hasFormClasses()) {
46         $entity_types[$entity_type_id] = [
47           'title' => $entity_type->getLabel(),
48           'url' => Url::fromRoute('entity.entity_form_mode.add_form', ['entity_type_id' => $entity_type_id]),
49           'localized_options' => [],
50         ];
51       }
52     }
53     return [
54       '#theme' => 'admin_block_content',
55       '#content' => $entity_types,
56     ];
57   }
58
59 }