diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index 0194765..12194a3 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -20,11 +20,6 @@ * @ConfigEntityType( * id = "entity_form_display", * label = @Translation("Entity form display"), - * handlers = { - * "form" = { - * "edit" = "Drupal\field_ui\Form\EntityFormDisplayEditForm" - * } - * }, * entity_keys = { * "id" = "id", * "status" = "status" diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php index aca27d5..1d62a54 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -21,11 +21,6 @@ * @ConfigEntityType( * id = "entity_view_display", * label = @Translation("Entity view display"), - * handlers = { - * "form" = { - * "edit" = "Drupal\field_ui\Form\EntityViewDisplayEditForm" - * } - * }, * entity_keys = { * "id" = "id", * "status" = "status" diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 07c27a8..009cb41 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -88,13 +88,15 @@ function field_ui_entity_type_build(array &$entity_types) { $entity_types['field_config']->setFormClass('delete', 'Drupal\field_ui\Form\FieldConfigDeleteForm'); $entity_types['field_config']->setListBuilderClass('Drupal\field_ui\FieldConfigListBuilder'); $entity_types['field_storage_config']->setListBuilderClass('Drupal\field_ui\FieldStorageConfigListBuilder'); + $entity_types['entity_form_display']->setFormClass('edit', 'Drupal\field_ui\Form\EntityFormDisplayEditForm'); + $entity_types['entity_view_display']->setFormClass('edit', 'Drupal\field_ui\Form\EntityViewDisplayEditForm'); foreach ($entity_types as $entity_type) { if ($bundle = $entity_type->getBundleOf()) { $entity_type ->setLinkTemplate('field_ui-fields', "field_ui.overview_$bundle") - ->setLinkTemplate('field_ui-form-display', "entity.entity_form_display.$bundle") - ->setLinkTemplate('field_ui-display', "entity.entity_view_display.$bundle"); + ->setLinkTemplate('field_ui-form-display', "entity.entity_form_display.$bundle.default") + ->setLinkTemplate('field_ui-display', "entity.entity_view_display.$bundle.default"); } } } diff --git a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php index ad46e39..5a936ab 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php +++ b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php @@ -11,10 +11,8 @@ use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\String; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; @@ -25,25 +23,11 @@ use Drupal\field_ui\FieldUI; /** - * Field UI display overview base class. + * Base class for EntityDisplay edit forms. */ abstract class EntityDisplayFormBase extends EntityForm { /** - * The name of the entity type. - * - * @var string - */ - protected $targetEntityTypeId; - - /** - * The entity bundle. - * - * @var string - */ - protected $targetBundle; - - /** * The name of the entity type which provides bundles for the entity type * defined above. * @@ -52,13 +36,6 @@ protected $bundleEntityTypeId; /** - * The entity manager. - * - * @var \Drupal\Core\Entity\EntityManagerInterface - */ - protected $entityManager; - - /** * The display context. Either 'view' or 'form'. * * @var string @@ -80,13 +57,6 @@ protected $fieldTypes; /** - * The config factory. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected $configFactory; - - /** * The entity being used by this form. * * @var \Drupal\Core\Entity\Display\EntityDisplayInterface @@ -96,39 +66,32 @@ /** * Constructs a new EntityDisplayFormBase. * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * The field type manager. * @param \Drupal\Component\Plugin\PluginManagerBase $plugin_manager * The widget or formatter plugin manager. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The configuration factory. */ - public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager, ConfigFactoryInterface $config_factory) { - $this->entityManager = $entity_manager; + public function __construct(FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager) { $this->fieldTypes = $field_type_manager->getDefinitions(); $this->pluginManager = $plugin_manager; - $this->configFactory = $config_factory; } /** * {@inheritdoc} */ public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) { - $route_paramateres = $route_match->getParameters()->all(); - $this->targetEntityTypeId = $route_paramateres['entity_type_id']; + $route_parameters = $route_match->getParameters()->all(); - if (isset($route_paramateres['bundle'])) { - $this->targetBundle = $route_paramateres['bundle']; + if (isset($route_parameters['bundle'])) { + $bundle = $route_parameters['bundle']; } else { - $target_entity_type = $this->entityManager->getDefinition($route_paramateres['entity_type_id']); + $target_entity_type = $this->entityManager->getDefinition($route_parameters['entity_type_id']); $this->bundleEntityTypeId = $target_entity_type->getBundleEntityType(); - $this->targetBundle = $route_paramateres[$this->bundleEntityTypeId]->id(); + $bundle = $route_parameters[$this->bundleEntityTypeId]->id(); } - return $this->getEntityDisplay($route_match->getParameter($this->displayContext . '_mode_name')); + return $this->getEntityDisplay($route_parameters['entity_type_id'], $bundle, $route_parameters[$this->displayContext . '_mode_name']); } /** @@ -186,7 +149,7 @@ public function getRegionOptions() { */ protected function getFieldDefinitions() { $context = $this->displayContext; - return array_filter($this->entityManager->getFieldDefinitions($this->targetEntityTypeId, $this->targetBundle), function(FieldDefinitionInterface $field_definition) use ($context) { + return array_filter($this->entityManager->getFieldDefinitions($this->entity->targetEntityType, $this->entity->bundle), function(FieldDefinitionInterface $field_definition) use ($context) { return $field_definition->isDisplayConfigurable($context); }); } @@ -197,20 +160,17 @@ protected function getFieldDefinitions() { public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); - $this->targetEntityTypeId = $this->entity->targetEntityType; - $this->targetBundle = $this->entity->bundle; - $field_definitions = $this->getFieldDefinitions(); $extra_fields = $this->getExtraFields(); $form += array( - '#entity_type' => $this->targetEntityTypeId, - '#bundle' => $this->targetBundle, + '#entity_type' => $this->entity->targetEntityType, + '#bundle' => $this->entity->bundle, '#fields' => array_keys($field_definitions), '#extra' => array_keys($extra_fields), ); - if (empty($field_definitions) && empty($extra_fields) && $route_info = FieldUI::getOverviewRouteInfo($this->targetEntityTypeId, $this->targetBundle)) { + if (empty($field_definitions) && empty($extra_fields) && $route_info = FieldUI::getOverviewRouteInfo($this->entity->targetEntityType, $this->entity->bundle)) { drupal_set_message($this->t('There are no fields yet added. You can add new fields on the Manage fields page.', array('@link' => $route_info->toString())), 'warning'); return $form; } @@ -588,8 +548,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // If no display exists for the newly enabled view mode, initialize // it with those from the 'default' view mode, which were used so // far. - if (!$this->entityManager->getStorage($this->entity->getEntityTypeId())->load($this->targetEntityTypeId . '.' . $this->targetBundle . '.' . $mode)) { - $display = $this->getEntityDisplay('default')->createCopy($mode); + if (!$this->entityManager->getStorage($this->entity->getEntityTypeId())->load($this->entity->targetEntityType . '.' . $this->entity->bundle . '.' . $mode)) { + $display = $this->getEntityDisplay($this->entity->targetEntityType, $this->entity->bundle, 'default')->createCopy($mode); $display->save(); } @@ -907,20 +867,24 @@ public function reduceOrder($array, $a) { */ protected function getExtraFields() { $context = $this->displayContext == 'view' ? 'display' : $this->displayContext; - $extra_fields = $this->entityManager->getExtraFields($this->targetEntityTypeId, $this->targetBundle); + $extra_fields = $this->entityManager->getExtraFields($this->entity->targetEntityType, $this->entity->bundle); return isset($extra_fields[$context]) ? $extra_fields[$context] : array(); } /** * Returns an entity display object to be used by this form. * + * @param string $entity_type_id + * The target entity type ID of the entity display. + * @param string $bundle + * The target bundle of the entity display. * @param string $mode * A view or form mode. * * @return \Drupal\Core\Entity\Display\EntityDisplayInterface * An entity display. */ - abstract protected function getEntityDisplay($mode); + abstract protected function getEntityDisplay($entity_type_id, $bundle, $mode); /** * Returns the widget or formatter plugin for a field. @@ -1016,7 +980,7 @@ protected function getDisplays() { $display_entity_type = $this->entity->getEntityTypeId(); $entity_type = $this->entityManager->getDefinition($display_entity_type); $config_prefix = $entity_type->getConfigPrefix(); - $ids = $this->configFactory->listAll($config_prefix . '.' . $this->targetEntityTypeId . '.' . $this->targetBundle . '.'); + $ids = $this->configFactory()->listAll($config_prefix . '.' . $this->entity->targetEntityType . '.' . $this->entity->bundle . '.'); foreach ($ids as $id) { $config_id = str_replace($config_prefix . '.', '', $id); list(,, $display_mode) = explode('.', $config_id); diff --git a/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php b/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php index 86864af..5b662fb 100644 --- a/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php +++ b/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php @@ -10,12 +10,11 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\PluginSettingsInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Field UI form display overview form. + * Edit form for the EntityFormDisplay entity type. */ class EntityFormDisplayEditForm extends EntityDisplayFormBase { @@ -29,10 +28,8 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase { */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager'), $container->get('plugin.manager.field.field_type'), - $container->get('plugin.manager.field.widget'), - $container->get('config.factory') + $container->get('plugin.manager.field.widget') ); } @@ -57,8 +54,8 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, arr /** * {@inheritdoc} */ - protected function getEntityDisplay($mode) { - return entity_get_form_display($this->targetEntityTypeId, $this->targetBundle, $mode); + protected function getEntityDisplay($entity_type_id, $bundle, $mode) { + return entity_get_form_display($entity_type_id, $bundle, $mode); } /** @@ -89,7 +86,7 @@ protected function getDefaultPlugin($field_type) { * {@inheritdoc} */ protected function getDisplayModes() { - return $this->entityManager->getFormModes($this->targetEntityTypeId); + return $this->entityManager->getFormModes($this->entity->targetEntityType); } /** @@ -108,8 +105,8 @@ protected function getTableHeader() { * {@inheritdoc} */ protected function getOverviewUrl($mode) { - return Url::fromRoute('entity.entity_form_display.form_mode_' . $this->targetEntityTypeId, [ - $this->bundleEntityTypeId => $this->targetBundle, + return Url::fromRoute('entity.entity_form_display.' . $this->entity->targetEntityType . '.form_mode', [ + $this->bundleEntityTypeId => $this->entity->bundle, 'form_mode_name' => $mode, ]); } diff --git a/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php b/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php index 7b9ee1a..f358f12 100644 --- a/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php +++ b/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php @@ -10,12 +10,11 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\PluginSettingsInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Field UI display overview form. + * Edit form for the EntityViewDisplay entity type. */ class EntityViewDisplayEditForm extends EntityDisplayFormBase { @@ -29,10 +28,8 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase { */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager'), $container->get('plugin.manager.field.field_type'), - $container->get('plugin.manager.field.formatter'), - $container->get('config.factory') + $container->get('plugin.manager.field.formatter') ); } @@ -90,8 +87,8 @@ protected function buildExtraFieldRow($field_id, $extra_field) { /** * {@inheritdoc} */ - protected function getEntityDisplay($mode) { - return entity_get_display($this->targetEntityTypeId, $this->targetBundle, $mode); + protected function getEntityDisplay($entity_type_id, $bundle, $mode) { + return entity_get_display($entity_type_id, $bundle, $mode); } /** @@ -122,7 +119,7 @@ protected function getDefaultPlugin($field_type) { * {@inheritdoc} */ protected function getDisplayModes() { - return $this->entityManager->getViewModes($this->targetEntityTypeId); + return $this->entityManager->getViewModes($this->entity->targetEntityType); } /** @@ -142,8 +139,8 @@ protected function getTableHeader() { * {@inheritdoc} */ protected function getOverviewUrl($mode) { - return Url::fromRoute('entity.entity_view_display.view_mode_' . $this->targetEntityTypeId, [ - $this->bundleEntityTypeId => $this->targetBundle, + return Url::fromRoute('entity.entity_view_display.' . $this->entity->targetEntityType . '.view_mode', [ + $this->bundleEntityTypeId => $this->entity->bundle, 'view_mode_name' => $mode, ]); } diff --git a/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php b/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php index eb33f91..562c2ec 100644 --- a/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php +++ b/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php @@ -79,7 +79,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { // 'Manage form display' tab. $this->derivatives["form_display_overview_$entity_type_id"] = array( - 'route_name' => "entity.entity_form_display.$entity_type_id", + 'route_name' => "entity.entity_form_display.$entity_type_id.default", 'weight' => 2, 'title' => $this->t('Manage form display'), 'base_route' => "field_ui.overview_$entity_type_id", @@ -87,7 +87,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { // 'Manage display' tab. $this->derivatives["display_overview_$entity_type_id"] = array( - 'route_name' => "entity.entity_view_display.$entity_type_id", + 'route_name' => "entity.entity_view_display.$entity_type_id.default", 'weight' => 3, 'title' => $this->t('Manage display'), 'base_route' => "field_ui.overview_$entity_type_id", @@ -116,13 +116,13 @@ public function getDerivativeDefinitions($base_plugin_definition) { // actually visible for a given bundle. $this->derivatives['field_form_display_default_' . $entity_type_id] = array( 'title' => 'Default', - 'route_name' => "entity.entity_form_display.$entity_type_id", + 'route_name' => "entity.entity_form_display.$entity_type_id.default", 'parent_id' => "field_ui.fields:form_display_overview_$entity_type_id", 'weight' => -1, ); $this->derivatives['field_display_default_' . $entity_type_id] = array( 'title' => 'Default', - 'route_name' => "entity.entity_view_display.$entity_type_id", + 'route_name' => "entity.entity_view_display.$entity_type_id.default", 'parent_id' => "field_ui.fields:display_overview_$entity_type_id", 'weight' => -1, ); @@ -132,7 +132,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->entityManager->getFormModes($entity_type_id) as $form_mode => $form_mode_info) { $this->derivatives['field_form_display_' . $form_mode . '_' . $entity_type_id] = array( 'title' => $form_mode_info['label'], - 'route_name' => "entity.entity_form_display.form_mode_$entity_type_id", + 'route_name' => "entity.entity_form_display.$entity_type_id.form_mode", 'route_parameters' => array( 'form_mode_name' => $form_mode, ), @@ -146,7 +146,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->entityManager->getViewModes($entity_type_id) as $view_mode => $form_mode_info) { $this->derivatives['field_display_' . $view_mode . '_' . $entity_type_id] = array( 'title' => $form_mode_info['label'], - 'route_name' => "entity.entity_view_display.view_mode_$entity_type_id", + 'route_name' => "entity.entity_view_display.$entity_type_id.view_mode", 'route_parameters' => array( 'view_mode_name' => $view_mode, ), diff --git a/core/modules/field_ui/src/Routing/RouteSubscriber.php b/core/modules/field_ui/src/Routing/RouteSubscriber.php index 171f688..96464c3 100644 --- a/core/modules/field_ui/src/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/src/Routing/RouteSubscriber.php @@ -118,7 +118,7 @@ protected function alterRoutes(RouteCollection $collection) { array('_field_ui_form_mode_access' => 'administer ' . $entity_type_id . ' form display'), $options ); - $collection->add("entity.entity_form_display.$entity_type_id", $route); + $collection->add("entity.entity_form_display.$entity_type_id.default", $route); $route = new Route( "$path/form-display/{form_mode_name}", @@ -129,7 +129,7 @@ protected function alterRoutes(RouteCollection $collection) { array('_field_ui_form_mode_access' => 'administer ' . $entity_type_id . ' form display'), $options ); - $collection->add("entity.entity_form_display.form_mode_$entity_type_id", $route); + $collection->add("entity.entity_form_display.$entity_type_id.form_mode", $route); $route = new Route( "$path/display", @@ -141,7 +141,7 @@ protected function alterRoutes(RouteCollection $collection) { array('_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display'), $options ); - $collection->add("entity.entity_view_display.$entity_type_id", $route); + $collection->add("entity.entity_view_display.$entity_type_id.default", $route); $route = new Route( "$path/display/{view_mode_name}", @@ -152,7 +152,7 @@ protected function alterRoutes(RouteCollection $collection) { array('_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display'), $options ); - $collection->add("entity.entity_view_display.view_mode_$entity_type_id", $route); + $collection->add("entity.entity_view_display.$entity_type_id.view_mode", $route); } } } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 4c0e36f..5480c39 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -100,13 +100,13 @@ function node_help($route_name, RouteMatchInterface $route_match) { case 'node.type_add': return '

' . t('Individual content types can have different fields, behaviors, and permissions assigned to them.') . '

'; - case 'entity.entity_form_display.node': - case 'entity.entity_form_display.form_mode_node': + case 'entity.entity_form_display.node.default': + case 'entity.entity_form_display.node.form_mode': $type = $route_match->getParameter('node_type'); return '

' . t('Content items can be edited using different form modes. Here, you can define which fields are shown and hidden when %type content is edited in each form mode, and define how the field form widgets are displayed in each form mode.', array('%type' => $type->label())) . '

' ; - case 'entity.entity_view_display.node': - case 'entity.entity_view_display.view_mode_node': + case 'entity.entity_view_display.node.default': + case 'entity.entity_view_display.node.view_mode': $type = $route_match->getParameter('node_type'); return '

' . t('Content items can be displayed using different view modes: Teaser, Full content, Print, RSS, etc. Teaser is a short format that is typically used in lists of multiple content items. Full content is typically used when the content is displayed on its own page.') . '

' . '

' . t('Here, you can define which fields are shown and hidden when %type content is displayed in each view mode, and define how the fields are displayed in each view mode.', array('%type' => $type->label())) . '

'; diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 0212446..eb67089 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -84,10 +84,10 @@ function user_help($route_name, RouteMatchInterface $route_match) { case 'field_ui.overview_user': return '

' . t('This form lets administrators add and edit fields for storing user data.') . '

'; - case 'entity.entity_form_display.user': + case 'entity.entity_form_display.user.default': return '

' . t('This form lets administrators configure how form fields should be displayed when editing a user profile.') . '

'; - case 'entity.entity_view_display.user': + case 'entity.entity_view_display.user.default': return '

' . t('This form lets administrators configure how fields should be displayed when rendering a user profile page.') . '

'; } }