diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index 12194a3..0194765 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -20,6 +20,11 @@ * @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 1d62a54..aca27d5 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -21,6 +21,11 @@ * @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 bdd492a..07c27a8 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -93,8 +93,8 @@ function field_ui_entity_type_build(array &$entity_types) { if ($bundle = $entity_type->getBundleOf()) { $entity_type ->setLinkTemplate('field_ui-fields', "field_ui.overview_$bundle") - ->setLinkTemplate('field_ui-form-display', "field_ui.form_display_overview_$bundle") - ->setLinkTemplate('field_ui-display', "field_ui.display_overview_$bundle"); + ->setLinkTemplate('field_ui-form-display', "entity.entity_form_display.$bundle") + ->setLinkTemplate('field_ui-display', "entity.entity_view_display.$bundle"); } } } diff --git a/core/modules/field_ui/src/DisplayOverviewBase.php b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php similarity index 89% rename from core/modules/field_ui/src/DisplayOverviewBase.php rename to core/modules/field_ui/src/Form/EntityDisplayFormBase.php index 09322d3..4f101a0 100644 --- a/core/modules/field_ui/src/DisplayOverviewBase.php +++ b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php @@ -2,44 +2,45 @@ /** * @file - * Contains \Drupal\field_ui\DisplayOverviewBase. + * Contains \Drupal\field_ui\Form\EntityDisplayFormBase. */ -namespace Drupal\field_ui; +namespace Drupal\field_ui\Form; use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\String; use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Entity\Display\EntityDisplayInterface; +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; use Drupal\Core\Field\PluginSettingsInterface; -use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Routing\RouteMatchInterface; /** * Field UI display overview base class. */ -abstract class DisplayOverviewBase extends FormBase { +abstract class EntityDisplayFormBase extends EntityForm { /** * The name of the entity type. * * @var string */ - protected $entity_type = ''; + protected $targetEntityTypeId; /** * The entity bundle. * * @var string */ - protected $bundle = ''; + protected $targetBundle; /** * The name of the entity type which provides bundles for the entity type @@ -50,13 +51,6 @@ protected $bundleEntityTypeId; /** - * The entity view or form mode. - * - * @var string - */ - protected $mode = ''; - - /** * The entity manager. * * @var \Drupal\Core\Entity\EntityManagerInterface @@ -92,7 +86,14 @@ protected $configFactory; /** - * Constructs a new DisplayOverviewBase. + * The entity being used by this form. + * + * @var \Drupal\Core\Entity\Display\EntityDisplayInterface + */ + protected $entity; + + /** + * Constructs a new EntityDisplayFormBase. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. @@ -113,13 +114,18 @@ public function __construct(EntityManagerInterface $entity_manager, FieldTypePlu /** * {@inheritdoc} */ - 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') - ); + public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) { + $route_paramateres = $route_match->getParameters()->all(); + $this->targetEntityTypeId = $route_paramateres['entity_type_id']; + + if (isset($route_paramateres['bundle'])) { + $this->targetBundle = $route_paramateres['bundle']; + } + else { + $target_entity_type = $this->entityManager->getDefinition($route_paramateres['entity_type_id']); + $this->bundleEntityTypeId = $target_entity_type->getBundleEntityType(); + $this->targetBundle = $route_paramateres[$this->bundleEntityTypeId]->id(); + } } /** @@ -177,7 +183,7 @@ public function getRegionOptions() { */ protected function getFieldDefinitions() { $context = $this->displayContext; - return array_filter($this->entityManager->getFieldDefinitions($this->entity_type, $this->bundle), function(FieldDefinitionInterface $field_definition) use ($context) { + return array_filter($this->entityManager->getFieldDefinitions($this->targetEntityTypeId, $this->targetBundle), function(FieldDefinitionInterface $field_definition) use ($context) { return $field_definition->isDisplayConfigurable($context); }); } @@ -185,32 +191,23 @@ protected function getFieldDefinitions() { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $mode = 'default') { - $entity_type = $this->entityManager->getDefinition($entity_type_id); - $this->bundleEntityTypeId = $entity_type->getBundleEntityType(); + public function form(array $form, FormStateInterface $form_state) { + $form = parent::form($form, $form_state); - if (!$form_state->get('bundle')) { - $bundle = $bundle ?: $this->getRequest()->attributes->get('_raw_variables')->get($this->bundleEntityTypeId); - $form_state->set('bundle', $bundle); - } - - $this->entity_type = $entity_type_id; - $this->bundle = $form_state->get('bundle'); - $this->mode = $mode; + $this->targetEntityTypeId = $this->entity->targetEntityType; + $this->targetBundle = $this->entity->bundle; $field_definitions = $this->getFieldDefinitions(); $extra_fields = $this->getExtraFields(); - $entity_display = $this->getEntityDisplay($this->mode); $form += array( - '#entity_type' => $this->entity_type, - '#bundle' => $this->bundle, - '#mode' => $this->mode, + '#entity_type' => $this->targetEntityTypeId, + '#bundle' => $this->targetBundle, '#fields' => array_keys($field_definitions), '#extra' => array_keys($extra_fields), ); - if (empty($field_definitions) && empty($extra_fields) && $route_info = FieldUI::getOverviewRouteInfo($this->entity_type, $this->bundle)) { + if (empty($field_definitions) && empty($extra_fields) && $route_info = FieldUI::getOverviewRouteInfo($this->targetEntityTypeId, $this->targetBundle)) { 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; } @@ -246,18 +243,18 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t // Field rows. foreach ($field_definitions as $field_name => $field_definition) { - $table[$field_name] = $this->buildFieldRow($field_definition, $entity_display, $form, $form_state); + $table[$field_name] = $this->buildFieldRow($field_definition, $form, $form_state); } // Non-field elements. foreach ($extra_fields as $field_id => $extra_field) { - $table[$field_id] = $this->buildExtraFieldRow($field_id, $extra_field, $entity_display); + $table[$field_id] = $this->buildExtraFieldRow($field_id, $extra_field); } $form['fields'] = $table; // Custom display settings. - if ($this->mode == 'default') { + if ($this->entity->mode == 'default') { // Only show the settings if there is at least one custom display mode. if ($display_modes = $this->getDisplayModes()) { $form['modes'] = array( @@ -324,8 +321,6 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t * * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition. - * @param \Drupal\Core\Entity\Display\EntityDisplayInterface $entity_display - * The entity display. * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state @@ -334,9 +329,9 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t * @return array * A table row array. */ - protected function buildFieldRow(FieldDefinitionInterface $field_definition, EntityDisplayInterface $entity_display, array $form, FormStateInterface $form_state) { + protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) { $field_name = $field_definition->getName(); - $display_options = $entity_display->getComponent($field_name); + $display_options = $this->entity->getComponent($field_name); $label = $field_definition->getLabel(); $regions = array_keys($this->getRegions()); @@ -514,14 +509,12 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent * The field ID. * @param array $extra_field * The pseudo-field element. - * @param \Drupal\Core\Entity\Display\EntityDisplayInterface $entity_display - * The entity display. * * @return array * A table row array. */ - protected function buildExtraFieldRow($field_id, $extra_field, EntityDisplayInterface $entity_display) { - $display_options = $entity_display->getComponent($field_id); + protected function buildExtraFieldRow($field_id, $extra_field) { + $display_options = $this->entity->getComponent($field_id); $regions = array_keys($this->getRegions()); $extra_field_row = array( @@ -578,8 +571,48 @@ protected function buildExtraFieldRow($field_id, $extra_field, EntityDisplayInte * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { + parent::submitForm($form, $form_state); $form_values = $form_state->getValues(); - $display = $this->getEntityDisplay($this->mode); + + // Handle the 'display modes' checkboxes if present. + if ($this->entity->mode == 'default' && !empty($form_values['display_modes_custom'])) { + $display_modes = $this->getDisplayModes(); + $current_statuses = $this->getDisplayStatuses(); + + $statuses = array(); + foreach ($form_values['display_modes_custom'] as $mode => $value) { + if (!empty($value) && empty($current_statuses[$mode])) { + // 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->entityManager->getStorage($this->entity->getEntityTypeId())->load($this->targetEntityTypeId . '.' . $this->targetBundle . '.' . 'default')->createCopy($mode); + $display->save(); + } + + $display_mode_label = $display_modes[$mode]['label']; + $url = $this->getOverviewUrl($mode); + drupal_set_message($this->t('The %display_mode mode now uses custom display settings. You might want to configure them.', ['%display_mode' => $display_mode_label, '@url' => $url->toString()])); + } + $statuses[$mode] = !empty($value); + } + + $this->saveDisplayStatuses($statuses); + } + + drupal_set_message($this->t('Your settings have been saved.')); + } + + /** + * {@inheritdoc} + */ + protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) { + $form_values = $form_state->getValues(); + + if ($this->entity instanceof EntityWithPluginCollectionInterface) { + // Do not manually update values represented by plugin collections. + $form_values = array_diff_key($form_values, $this->entity->getPluginCollections()); + } // Collect data for 'regular' fields. foreach ($form['#fields'] as $field_name) { @@ -588,7 +621,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $values = $form_values['fields'][$field_name]; if ($values['type'] == 'hidden') { - $display->removeComponent($field_name); + $entity->removeComponent($field_name); } else { // Get plugin settings. They lie either directly in submitted form @@ -602,7 +635,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { elseif (isset($plugin_settings[$field_name]['settings'])) { $settings = $plugin_settings[$field_name]['settings']; } - elseif ($current_options = $display->getComponent($field_name)) { + elseif ($current_options = $entity->getComponent($field_name)) { $settings = $current_options['settings']; } $third_party_settings = array(); @@ -612,7 +645,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { elseif (isset($plugin_settings[$field_name]['third_party_settings'])) { $third_party_settings = $plugin_settings[$field_name]['third_party_settings']; } - elseif (($current_options = $display->getComponent($field_name)) && isset($current_options['third_party_settings'])) { + elseif (($current_options = $entity->getComponent($field_name)) && isset($current_options['third_party_settings'])) { $third_party_settings = $current_options['third_party_settings']; } @@ -633,52 +666,21 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $component_values['label'] = $values['label']; } - $display->setComponent($field_name, $component_values); + $entity->setComponent($field_name, $component_values); } } // Collect data for 'extra' fields. foreach ($form['#extra'] as $name) { if ($form_values['fields'][$name]['type'] == 'hidden') { - $display->removeComponent($name); + $entity->removeComponent($name); } else { - $display->setComponent($name, array( + $entity->setComponent($name, array( 'weight' => $form_values['fields'][$name]['weight'], )); } } - - // Save the display. - $display->save(); - - // Handle the 'display modes' checkboxes if present. - if ($this->mode == 'default' && !empty($form_values['display_modes_custom'])) { - $display_modes = $this->getDisplayModes(); - $current_statuses = $this->getDisplayStatuses(); - - $statuses = array(); - foreach ($form_values['display_modes_custom'] as $mode => $value) { - if (!empty($value) && empty($current_statuses[$mode])) { - // 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 (!entity_load($this->getEntityDisplay('default')->getEntityTypeId(), $this->entity_type . '.' . $this->bundle . '.' . $mode)) { - $display = $this->getEntityDisplay('default')->createCopy($mode); - $display->save(); - } - - $display_mode_label = $display_modes[$mode]['label']; - $url = $this->getOverviewRoute($mode); - drupal_set_message($this->t('The %display_mode mode now uses custom display settings. You might want to configure them.', ['%display_mode' => $display_mode_label, '@url' => $url->toString()])); - } - $statuses[$mode] = !empty($value); - } - - $this->saveDisplayStatuses($statuses); - } - - drupal_set_message($this->t('Your settings have been saved.')); } /** @@ -865,7 +867,7 @@ public function tablePreRender($elements) { * Determines the rendering order of an array representing a tree. * * Callback for array_reduce() within - * \Drupal\field_ui\DisplayOverviewBase::tablePreRender(). + * \Drupal\field_ui\Form\EntityDisplayFormBase::tablePreRender(). */ public function reduceOrder($array, $a) { $array = !isset($array) ? array() : $array; @@ -880,17 +882,6 @@ public function reduceOrder($array, $a) { } /** - * Returns the entity display object used by this form. - * - * @param string $mode - * A view or form mode. - * - * @return \Drupal\Core\Entity\Display\EntityDisplayInterface - * An entity display. - */ - abstract protected function getEntityDisplay($mode); - - /** * Returns the extra fields of the entity type and bundle used by this form. * * @return array @@ -900,7 +891,7 @@ public function reduceOrder($array, $a) { */ protected function getExtraFields() { $context = $this->displayContext == 'view' ? 'display' : $this->displayContext; - $extra_fields = $this->entityManager->getExtraFields($this->entity_type, $this->bundle); + $extra_fields = $this->entityManager->getExtraFields($this->targetEntityTypeId, $this->targetBundle); return isset($extra_fields[$context]) ? $extra_fields[$context] : array(); } @@ -935,7 +926,7 @@ protected function getPluginOptions(FieldDefinitionInterface $field_definition) $applicable_options[$option] = $label; } } - return $applicable_options; + return $applicable_options + array('hidden' => '- ' . $this->t('Hidden') . ' -'); } /** @@ -958,14 +949,6 @@ protected function getPluginOptions(FieldDefinitionInterface $field_definition) abstract protected function getDisplayModes(); /** - * Returns the display entity type. - * - * @return string - * The name of the display entity type. - */ - abstract protected function getDisplayType(); - - /** * Returns the region to which a row in the display overview belongs. * * @param array $row @@ -998,15 +981,15 @@ protected function getExtraFieldVisibilityOptions() { /** * Returns entity (form) displays for the current entity display type. * - * @return array + * @return \Drupal\Core\Entity\Display\EntityDisplayInterface[] * An array holding entity displays or entity form displays. */ protected function getDisplays() { $load_ids = array(); - $display_entity_type = $this->getDisplayType(); + $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->entity_type . '.' . $this->bundle . '.'); + $ids = $this->configFactory->listAll($config_prefix . '.' . $this->targetEntityTypeId . '.' . $this->targetBundle . '.'); foreach ($ids as $id) { $config_id = str_replace($config_prefix . '.', '', $id); list(,, $display_mode) = explode('.', $config_id); @@ -1014,7 +997,7 @@ protected function getDisplays() { $load_ids[] = $config_id; } } - return entity_load_multiple($display_entity_type, $load_ids); + return $this->entityManager->getStorage($display_entity_type)->loadMultiple($load_ids); } /** @@ -1055,7 +1038,7 @@ protected function saveDisplayStatuses($display_statuses) { abstract protected function getTableHeader(); /** - * Returns the route info of a specific form or view mode form. + * Returns the Url object for a specific entity (form) display edit form. * * @param string $mode * The form or view mode. @@ -1063,7 +1046,7 @@ protected function saveDisplayStatuses($display_statuses) { * @return \Drupal\Core\Url * A Url object for the overview route. */ - abstract protected function getOverviewRoute($mode); + abstract protected function getOverviewUrl($mode); /** * Adds the widget or formatter third party settings forms. diff --git a/core/modules/field_ui/src/FormDisplayOverview.php b/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php similarity index 53% rename from core/modules/field_ui/src/FormDisplayOverview.php rename to core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php index 1728044..9a6f57e 100644 --- a/core/modules/field_ui/src/FormDisplayOverview.php +++ b/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php @@ -2,27 +2,22 @@ /** * @file - * Contains \Drupal\field_ui\FormDisplayOverview. + * Contains \Drupal\field_ui\Form\EntityFormDisplayEditForm. */ -namespace Drupal\field_ui; +namespace Drupal\field_ui\Form; -use Drupal\Component\Plugin\PluginManagerBase; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Entity\Display\EntityDisplayInterface; -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Field\FieldDefinitionInterface; -use Drupal\Core\Field\FieldTypePluginManager; 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. */ -class FormDisplayOverview extends DisplayOverviewBase { +class EntityFormDisplayEditForm extends EntityDisplayFormBase { /** * {@inheritdoc} @@ -30,32 +25,6 @@ class FormDisplayOverview extends DisplayOverviewBase { protected $displayContext = 'form'; /** - * Stores the module manager. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * Constructs a new class instance. - * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. - * @param \Drupal\Core\Field\FieldTypePluginManager $field_type_manager - * The field type manager. - * @param \Drupal\Component\Plugin\PluginManagerBase $plugin_manager - * The widget or formatter plugin manager. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler to use for invoking hooks. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The configuration factory. - */ - public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManager $field_type_manager, PluginManagerBase $plugin_manager, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) { - parent::__construct($entity_manager, $field_type_manager, $plugin_manager, $config_factory); - $this->moduleHandler = $module_handler; - } - - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { @@ -63,7 +32,6 @@ public static function create(ContainerInterface $container) { $container->get('entity.manager'), $container->get('plugin.manager.field.field_type'), $container->get('plugin.manager.field.widget'), - $container->get('module_handler'), $container->get('config.factory') ); } @@ -71,28 +39,23 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getFormId() { - return 'field_ui_form_display_overview_form'; - } + public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) { + parent::getEntityFromRouteMatch($route_match, $entity_type_id); - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $form_mode_name = 'default') { - return parent::buildForm($form, $form_state, $entity_type_id, $bundle, $form_mode_name); + return entity_get_form_display($this->targetEntityTypeId, $this->targetBundle, $route_match->getParameter('form_mode_name')); } /** * {@inheritdoc} */ - protected function buildFieldRow(FieldDefinitionInterface $field_definition, EntityDisplayInterface $entity_display, array $form, FormStateInterface $form_state) { - $field_row = parent::buildFieldRow($field_definition, $entity_display, $form, $form_state); + protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) { + $field_row = parent::buildFieldRow($field_definition, $form, $form_state); $field_name = $field_definition->getName(); // Update the (invisible) title of the 'plugin' column. $field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $field_definition->getLabel())); - if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $entity_display->getRenderer($field_name))) { + if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $this->entity->getRenderer($field_name))) { $plugin_type_info = $plugin->getPluginDefinition(); $field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Widget settings:') . ' ' . $plugin_type_info['label'] . ''; } @@ -103,20 +66,13 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent /** * {@inheritdoc} */ - protected function getEntityDisplay($mode) { - return entity_get_form_display($this->entity_type, $this->bundle, $mode); - } - - /** - * {@inheritdoc} - */ protected function getPlugin(FieldDefinitionInterface $field_definition, $configuration) { $plugin = NULL; if ($configuration && $configuration['type'] != 'hidden') { $plugin = $this->pluginManager->getInstance(array( 'field_definition' => $field_definition, - 'form_mode' => $this->mode, + 'form_mode' => $this->entity->mode, 'configuration' => $configuration )); } @@ -127,13 +83,6 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config /** * {@inheritdoc} */ - protected function getPluginOptions(FieldDefinitionInterface $field_definition) { - return parent::getPluginOptions($field_definition) + array('hidden' => '- ' . t('Hidden') . ' -'); - } - - /** - * {@inheritdoc} - */ protected function getDefaultPlugin($field_type) { return isset($this->fieldTypes[$field_type]['default_widget']) ? $this->fieldTypes[$field_type]['default_widget'] : NULL; } @@ -142,14 +91,7 @@ protected function getDefaultPlugin($field_type) { * {@inheritdoc} */ protected function getDisplayModes() { - return $this->entityManager->getFormModes($this->entity_type); - } - - /** - * {@inheritdoc} - */ - protected function getDisplayType() { - return 'entity_form_display'; + return $this->entityManager->getFormModes($this->targetEntityTypeId); } /** @@ -167,9 +109,9 @@ protected function getTableHeader() { /** * {@inheritdoc} */ - protected function getOverviewRoute($mode) { - return Url::fromRoute('field_ui.form_display_overview_form_mode_' . $this->entity_type, [ - $this->bundleEntityTypeId => $this->bundle, + protected function getOverviewUrl($mode) { + return Url::fromRoute('entity.entity_form_display.form_mode_' . $this->targetEntityTypeId, [ + $this->bundleEntityTypeId => $this->targetBundle, 'form_mode_name' => $mode, ]); } @@ -185,7 +127,7 @@ protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, Field $settings_form[$module] = $this->moduleHandler->invoke($module, 'field_widget_third_party_settings_form', array( $plugin, $field_definition, - $this->mode, + $this->entity->mode, $form, $form_state, )); @@ -200,7 +142,7 @@ protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $context = array( 'widget' => $plugin, 'field_definition' => $field_definition, - 'form_mode' => $this->mode, + 'form_mode' => $this->entity->mode, ); $this->moduleHandler->alter('field_widget_settings_summary', $summary, $context); } diff --git a/core/modules/field_ui/src/DisplayOverview.php b/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php similarity index 60% rename from core/modules/field_ui/src/DisplayOverview.php rename to core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php index b302529..a441ad0 100644 --- a/core/modules/field_ui/src/DisplayOverview.php +++ b/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php @@ -2,28 +2,22 @@ /** * @file - * Contains \Drupal\field_ui\DisplayOverview. + * Contains \Drupal\field_ui\Form\EntityViewDisplayEditForm. */ -namespace Drupal\field_ui; +namespace Drupal\field_ui\Form; -use Drupal\Component\Plugin\PluginManagerBase; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Field\FieldDefinitionInterface; -use Drupal\Core\Entity\Display\EntityDisplayInterface; -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Field\FieldTypePluginManager; -use Drupal\Core\Field\FormatterInterface; 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. */ -class DisplayOverview extends DisplayOverviewBase { +class EntityViewDisplayEditForm extends EntityDisplayFormBase { /** * {@inheritdoc} @@ -31,32 +25,6 @@ class DisplayOverview extends DisplayOverviewBase { protected $displayContext = 'view'; /** - * Stores the module manager. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * Constructs a new class instance. - * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. - * @param \Drupal\Core\Field\FieldTypePluginManager $field_type_manager - * The field type manager. - * @param \Drupal\Component\Plugin\PluginManagerBase $plugin_manager - * The widget or formatter plugin manager. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler class to use for invoking hooks. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The configuration factory. - */ - public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManager $field_type_manager, PluginManagerBase $plugin_manager, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) { - parent::__construct($entity_manager, $field_type_manager, $plugin_manager, $config_factory); - $this->moduleHandler = $module_handler; - } - - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { @@ -64,33 +32,27 @@ public static function create(ContainerInterface $container) { $container->get('entity.manager'), $container->get('plugin.manager.field.field_type'), $container->get('plugin.manager.field.formatter'), - $container->get('module_handler'), $container->get('config.factory') - ); + ); } /** * {@inheritdoc} */ - public function getFormId() { - return 'field_ui_display_overview_form'; - } + public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) { + parent::getEntityFromRouteMatch($route_match, $entity_type_id); - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $view_mode_name = 'default') { - return parent::buildForm($form, $form_state, $entity_type_id, $bundle, $view_mode_name); + return entity_get_display($this->targetEntityTypeId, $this->targetBundle, $route_match->getParameter('view_mode_name')); } /** * {@inheritdoc} */ - protected function buildFieldRow(FieldDefinitionInterface $field_definition, EntityDisplayInterface $entity_display, array $form, FormStateInterface $form_state) { - $field_row = parent::buildFieldRow($field_definition, $entity_display, $form, $form_state); + protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) { + $field_row = parent::buildFieldRow($field_definition, $form, $form_state); $field_name = $field_definition->getName(); - $display_options = $entity_display->getComponent($field_name); + $display_options = $this->entity->getComponent($field_name); // Insert the label column. $label = array( @@ -108,7 +70,7 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent // Update the (invisible) title of the 'plugin' column. $field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $field_definition->getLabel())); - if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $entity_display->getRenderer($field_name))) { + if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $this->entity->getRenderer($field_name))) { $plugin_type_info = $plugin->getPluginDefinition(); $field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Format settings:') . ' ' . $plugin_type_info['label'] . ''; } @@ -119,8 +81,8 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent /** * {@inheritdoc} */ - protected function buildExtraFieldRow($field_id, $extra_field, EntityDisplayInterface $entity_display) { - $extra_field_row = parent::buildExtraFieldRow($field_id, $extra_field, $entity_display); + protected function buildExtraFieldRow($field_id, $extra_field) { + $extra_field_row = parent::buildExtraFieldRow($field_id, $extra_field); // Insert an empty placeholder for the label column. $label = array( @@ -137,20 +99,13 @@ protected function buildExtraFieldRow($field_id, $extra_field, EntityDisplayInte /** * {@inheritdoc} */ - protected function getEntityDisplay($mode) { - return entity_get_display($this->entity_type, $this->bundle, $mode); - } - - /** - * {@inheritdoc} - */ protected function getPlugin(FieldDefinitionInterface $field_definition, $configuration) { $plugin = NULL; if ($configuration && $configuration['type'] != 'hidden') { $plugin = $this->pluginManager->getInstance(array( 'field_definition' => $field_definition, - 'view_mode' => $this->mode, + 'view_mode' => $this->entity->mode, 'configuration' => $configuration )); } @@ -161,13 +116,6 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config /** * {@inheritdoc} */ - protected function getPluginOptions(FieldDefinitionInterface $field_definition) { - return parent::getPluginOptions($field_definition) + array('hidden' => '- ' . $this->t('Hidden') . ' -'); - } - - /** - * {@inheritdoc} - */ protected function getDefaultPlugin($field_type) { return isset($this->fieldTypes[$field_type]['default_formatter']) ? $this->fieldTypes[$field_type]['default_formatter'] : NULL; } @@ -176,14 +124,7 @@ protected function getDefaultPlugin($field_type) { * {@inheritdoc} */ protected function getDisplayModes() { - return $this->entityManager->getViewModes($this->entity_type); - } - - /** - * {@inheritdoc} - */ - protected function getDisplayType() { - return 'entity_view_display'; + return $this->entityManager->getViewModes($this->targetEntityTypeId); } /** @@ -202,9 +143,9 @@ protected function getTableHeader() { /** * {@inheritdoc} */ - protected function getOverviewRoute($mode) { - return Url::fromRoute('field_ui.display_overview_view_mode_' . $this->entity_type, [ - $this->bundleEntityTypeId => $this->bundle, + protected function getOverviewUrl($mode) { + return Url::fromRoute('entity.entity_view_display.view_mode_' . $this->targetEntityTypeId, [ + $this->bundleEntityTypeId => $this->targetBundle, 'view_mode_name' => $mode, ]); } @@ -235,7 +176,7 @@ protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, Field $settings_form[$module] = $this->moduleHandler->invoke($module, 'field_formatter_third_party_settings_form', array( $plugin, $field_definition, - $this->mode, + $this->entity->mode, $form, $form_state, )); @@ -250,7 +191,7 @@ protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $context = array( 'formatter' => $plugin, 'field_definition' => $field_definition, - 'view_mode' => $this->mode, + 'view_mode' => $this->entity->mode, ); $this->moduleHandler->alter('field_formatter_settings_summary', $summary, $context); } diff --git a/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php b/core/modules/field_ui/src/Plugin/Derivative/FieldUiLocalTask.php index 5d56924..eb33f91 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' => "field_ui.form_display_overview_$entity_type_id", + 'route_name' => "entity.entity_form_display.$entity_type_id", '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' => "field_ui.display_overview_$entity_type_id", + 'route_name' => "entity.entity_view_display.$entity_type_id", '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' => "field_ui.form_display_overview_$entity_type_id", + 'route_name' => "entity.entity_form_display.$entity_type_id", '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' => "field_ui.display_overview_$entity_type_id", + 'route_name' => "entity.entity_view_display.$entity_type_id", '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' => "field_ui.form_display_overview_form_mode_$entity_type_id", + 'route_name' => "entity.entity_form_display.form_mode_$entity_type_id", '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' => "field_ui.display_overview_view_mode_$entity_type_id", + 'route_name' => "entity.entity_view_display.view_mode_$entity_type_id", '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 5e9c265..171f688 100644 --- a/core/modules/field_ui/src/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/src/Routing/RouteSubscriber.php @@ -111,46 +111,48 @@ protected function alterRoutes(RouteCollection $collection) { $route = new Route( "$path/form-display", array( - '_form' => '\Drupal\field_ui\FormDisplayOverview', + '_entity_form' => 'entity_form_display.edit', '_title' => 'Manage form display', + 'form_mode_name' => 'default', ) + $defaults, array('_field_ui_form_mode_access' => 'administer ' . $entity_type_id . ' form display'), $options ); - $collection->add("field_ui.form_display_overview_$entity_type_id", $route); + $collection->add("entity.entity_form_display.$entity_type_id", $route); $route = new Route( "$path/form-display/{form_mode_name}", array( - '_form' => '\Drupal\field_ui\FormDisplayOverview', + '_entity_form' => 'entity_form_display.edit', '_title' => 'Manage form display', ) + $defaults, array('_field_ui_form_mode_access' => 'administer ' . $entity_type_id . ' form display'), $options ); - $collection->add("field_ui.form_display_overview_form_mode_$entity_type_id", $route); + $collection->add("entity.entity_form_display.form_mode_$entity_type_id", $route); $route = new Route( "$path/display", array( - '_form' => '\Drupal\field_ui\DisplayOverview', + '_entity_form' => 'entity_view_display.edit', '_title' => 'Manage display', + 'view_mode_name' => 'default', ) + $defaults, array('_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display'), $options ); - $collection->add("field_ui.display_overview_$entity_type_id", $route); + $collection->add("entity.entity_view_display.$entity_type_id", $route); $route = new Route( "$path/display/{view_mode_name}", array( - '_form' => '\Drupal\field_ui\DisplayOverview', + '_entity_form' => 'entity_view_display.edit', '_title' => 'Manage display', ) + $defaults, array('_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display'), $options ); - $collection->add("field_ui.display_overview_view_mode_$entity_type_id", $route); + $collection->add("entity.entity_view_display.view_mode_$entity_type_id", $route); } } } diff --git a/core/modules/field_ui/src/Tests/ManageDisplayTest.php b/core/modules/field_ui/src/Tests/ManageDisplayTest.php index e628757..c09d894 100644 --- a/core/modules/field_ui/src/Tests/ManageDisplayTest.php +++ b/core/modules/field_ui/src/Tests/ManageDisplayTest.php @@ -164,6 +164,7 @@ function testFormatterUI() { // is no longer there. \Drupal::service('module_installer')->uninstall(array('field_third_party_test')); $this->drupalGet($manage_display); + $this->assertResponse(200); $this->assertNoFieldByName('field_test_settings_edit'); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 3a75398..fb876cd 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 'field_ui.form_display_overview_node': - case 'field_ui.form_display_overview_form_mode_node': + case 'entity.entity_form_display.node': + case 'entity.entity_form_display.form_mode_node': $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 'field_ui.display_overview_node': - case 'field_ui.display_overview_view_mode_node': + case 'entity.entity_view_display.node': + case 'entity.entity_view_display.view_mode_node': $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 a251fd7..0212446 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 'field_ui.form_display_overview_user': + case 'entity.entity_form_display.user': return '

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

'; - case 'field_ui.display_overview_user': + case 'entity.entity_view_display.user': return '

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

'; } }