Commit b8378ac5 authored by alexpott's avatar alexpott

Issue #2094499 by amateescu: Convert "Manage (form) display" forms to be the...

Issue #2094499 by amateescu: Convert "Manage (form) display" forms to be the official entity edit forms for EntityView[Form]Display objects
parent 17bf38b9
...@@ -54,9 +54,6 @@ core.entity_view_display.*.*.*: ...@@ -54,9 +54,6 @@ core.entity_view_display.*.*.*:
id: id:
type: string type: string
label: 'ID' label: 'ID'
label:
type: label
label: 'Label'
targetEntityType: targetEntityType:
type: string type: string
label: 'Target entity type' label: 'Target entity type'
......
...@@ -399,6 +399,7 @@ public function __sleep() { ...@@ -399,6 +399,7 @@ public function __sleep() {
// Only store the definition, not external objects or derived data. // Only store the definition, not external objects or derived data.
$keys = array_keys($this->toArray()); $keys = array_keys($this->toArray());
$keys[] = 'entityTypeId'; $keys[] = 'entityTypeId';
$keys[] = 'enforceIsNew';
return $keys; return $keys;
} }
...@@ -408,7 +409,9 @@ public function __sleep() { ...@@ -408,7 +409,9 @@ public function __sleep() {
public function __wakeup() { public function __wakeup() {
// Run the values from self::toArray() through __construct(). // Run the values from self::toArray() through __construct().
$values = array_intersect_key($this->toArray(), get_object_vars($this)); $values = array_intersect_key($this->toArray(), get_object_vars($this));
$is_new = $this->isNew();
$this->__construct($values, $this->entityTypeId); $this->__construct($values, $this->entityTypeId);
$this->enforceIsNew($is_new);
} }
} }
...@@ -8,7 +8,6 @@ dependencies: ...@@ -8,7 +8,6 @@ dependencies:
- text - text
- user - user
id: node.book.default id: node.book.default
label: null
targetEntityType: node targetEntityType: node
bundle: book bundle: book
mode: default mode: default
......
...@@ -9,7 +9,6 @@ dependencies: ...@@ -9,7 +9,6 @@ dependencies:
- text - text
- user - user
id: node.book.teaser id: node.book.teaser
label: null
targetEntityType: node targetEntityType: node
bundle: book bundle: book
mode: teaser mode: teaser
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityViewModeInterface; use Drupal\Core\Entity\EntityViewModeInterface;
use Drupal\Core\Url;
use Drupal\field_ui\FieldUI; use Drupal\field_ui\FieldUI;
use Drupal\field_ui\Plugin\Derivative\FieldUiLocalTask; use Drupal\field_ui\Plugin\Derivative\FieldUiLocalTask;
...@@ -68,6 +69,8 @@ function field_ui_entity_type_build(array &$entity_types) { ...@@ -68,6 +69,8 @@ function field_ui_entity_type_build(array &$entity_types) {
$entity_types['field_config']->setListBuilderClass('Drupal\field_ui\FieldConfigListBuilder'); $entity_types['field_config']->setListBuilderClass('Drupal\field_ui\FieldConfigListBuilder');
$entity_types['field_storage_config']->setListBuilderClass('Drupal\field_ui\FieldStorageConfigListBuilder'); $entity_types['field_storage_config']->setListBuilderClass('Drupal\field_ui\FieldStorageConfigListBuilder');
$entity_types['field_storage_config']->setLinkTemplate('collection', '/admin/reports/fields'); $entity_types['field_storage_config']->setLinkTemplate('collection', '/admin/reports/fields');
$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) { foreach ($entity_types as $entity_type) {
if ($bundle = $entity_type->getBundleOf()) { if ($bundle = $entity_type->getBundleOf()) {
...@@ -76,9 +79,7 @@ function field_ui_entity_type_build(array &$entity_types) { ...@@ -76,9 +79,7 @@ function field_ui_entity_type_build(array &$entity_types) {
// This allows us to not require route information inside this hook, which // This allows us to not require route information inside this hook, which
// otherwise could result in circular dependencies. // otherwise could result in circular dependencies.
$entity_type $entity_type
->setLinkTemplate('field_ui-fields', "/admin/{$entity_type->id()}/fields") ->setLinkTemplate('field_ui-fields', "/admin/{$entity_type->id()}/fields");
->setLinkTemplate('field_ui-form-display', "/admin/{$entity_type->id()}/fields-form-display")
->setLinkTemplate('field_ui-display', "/admin/{$entity_type->id()}/fields-display");
} }
} }
} }
...@@ -143,14 +144,18 @@ function field_ui_entity_operation(EntityInterface $entity) { ...@@ -143,14 +144,18 @@ function field_ui_entity_operation(EntityInterface $entity) {
$operations['manage-form-display'] = array( $operations['manage-form-display'] = array(
'title' => t('Manage form display'), 'title' => t('Manage form display'),
'weight' => 20, 'weight' => 20,
'url' => $entity->urlInfo('field_ui-form-display'), 'url' => Url::fromRoute("entity.entity_form_display.{$entity->getEntityTypeId()}.default", array(
$entity->getEntityTypeId() => $entity->id(),
)),
); );
} }
if ($account->hasPermission('administer '. $bundle_of . ' display')) { if ($account->hasPermission('administer '. $bundle_of . ' display')) {
$operations['manage-display'] = array( $operations['manage-display'] = array(
'title' => t('Manage display'), 'title' => t('Manage display'),
'weight' => 25, 'weight' => 25,
'url' => $entity->urlInfo('field_ui-display'), 'url' => Url::fromRoute("entity.entity_view_display.{$entity->getEntityTypeId()}.default", array(
$entity->getEntityTypeId() => $entity->id(),
)),
); );
} }
} }
......
...@@ -2,97 +2,48 @@ ...@@ -2,97 +2,48 @@
/** /**
* @file * @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\FieldDefinitionInterface;
use Drupal\Core\Field\FieldTypePluginManager;
use Drupal\Core\Field\PluginSettingsInterface; use Drupal\Core\Field\PluginSettingsInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Field UI form display overview form. * Edit form for the EntityFormDisplay entity type.
*/ */
class FormDisplayOverview extends DisplayOverviewBase { class EntityFormDisplayEditForm extends EntityDisplayFormBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected $displayContext = 'form'; 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} * {@inheritdoc}
*/ */
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('entity.manager'),
$container->get('plugin.manager.field.field_type'), $container->get('plugin.manager.field.field_type'),
$container->get('plugin.manager.field.widget'), $container->get('plugin.manager.field.widget')
$container->get('module_handler'),
$container->get('config.factory')
); );
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getFormId() { protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
return 'field_ui_form_display_overview_form'; $field_row = parent::buildFieldRow($field_definition, $form, $form_state);
}
/**
* {@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);
}
/**
* {@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);
$field_name = $field_definition->getName(); $field_name = $field_definition->getName();
// Update the (invisible) title of the 'plugin' column. // Update the (invisible) title of the 'plugin' column.
$field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $field_definition->getLabel())); $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(); $plugin_type_info = $plugin->getPluginDefinition();
$field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Widget settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>'; $field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Widget settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>';
} }
...@@ -103,8 +54,8 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent ...@@ -103,8 +54,8 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function getEntityDisplay($mode) { protected function getEntityDisplay($entity_type_id, $bundle, $mode) {
return entity_get_form_display($this->entity_type, $this->bundle, $mode); return entity_get_form_display($entity_type_id, $bundle, $mode);
} }
/** /**
...@@ -116,7 +67,7 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config ...@@ -116,7 +67,7 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config
if ($configuration && $configuration['type'] != 'hidden') { if ($configuration && $configuration['type'] != 'hidden') {
$plugin = $this->pluginManager->getInstance(array( $plugin = $this->pluginManager->getInstance(array(
'field_definition' => $field_definition, 'field_definition' => $field_definition,
'form_mode' => $this->mode, 'form_mode' => $this->entity->mode,
'configuration' => $configuration 'configuration' => $configuration
)); ));
} }
...@@ -124,13 +75,6 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config ...@@ -124,13 +75,6 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config
return $plugin; return $plugin;
} }
/**
* {@inheritdoc}
*/
protected function getPluginOptions(FieldDefinitionInterface $field_definition) {
return parent::getPluginOptions($field_definition) + array('hidden' => '- ' . t('Hidden') . ' -');
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -142,14 +86,7 @@ protected function getDefaultPlugin($field_type) { ...@@ -142,14 +86,7 @@ protected function getDefaultPlugin($field_type) {
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function getDisplayModes() { protected function getDisplayModes() {
return $this->entityManager->getFormModes($this->entity_type); return $this->entityManager->getFormModes($this->entity->targetEntityType);
}
/**
* {@inheritdoc}
*/
protected function getDisplayType() {
return 'entity_form_display';
} }
/** /**
...@@ -167,11 +104,11 @@ protected function getTableHeader() { ...@@ -167,11 +104,11 @@ protected function getTableHeader() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function getOverviewRoute($mode) { protected function getOverviewUrl($mode) {
$entity_type = $this->entityManager->getDefinition($this->entity_type); $entity_type = $this->entityManager->getDefinition($this->entity->targetEntityType);
$field_entity_type = $entity_type->getBundleEntityType() != 'bundle'? $entity_type->getBundleEntityType() : $entity_type->id(); $field_entity_type = $entity_type->getBundleEntityType() != 'bundle'? $entity_type->getBundleEntityType() : $entity_type->id();
return Url::fromRoute('field_ui.form_display_overview_form_mode_' . $field_entity_type, [ return Url::fromRoute('entity.entity_form_display.' . $field_entity_type . '.form_mode', [
$this->bundleEntityTypeId => $this->bundle, $this->bundleEntityTypeId => $this->entity->bundle,
'form_mode_name' => $mode, 'form_mode_name' => $mode,
]); ]);
} }
...@@ -187,7 +124,7 @@ protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, Field ...@@ -187,7 +124,7 @@ protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, Field
$settings_form[$module] = $this->moduleHandler->invoke($module, 'field_widget_third_party_settings_form', array( $settings_form[$module] = $this->moduleHandler->invoke($module, 'field_widget_third_party_settings_form', array(
$plugin, $plugin,
$field_definition, $field_definition,
$this->mode, $this->entity->mode,
$form, $form,
$form_state, $form_state,
)); ));
...@@ -202,7 +139,7 @@ protected function alterSettingsSummary(array &$summary, PluginSettingsInterface ...@@ -202,7 +139,7 @@ protected function alterSettingsSummary(array &$summary, PluginSettingsInterface
$context = array( $context = array(
'widget' => $plugin, 'widget' => $plugin,
'field_definition' => $field_definition, 'field_definition' => $field_definition,
'form_mode' => $this->mode, 'form_mode' => $this->entity->mode,
); );
$this->moduleHandler->alter('field_widget_settings_summary', $summary, $context); $this->moduleHandler->alter('field_widget_settings_summary', $summary, $context);
} }
......
...@@ -2,95 +2,45 @@ ...@@ -2,95 +2,45 @@
/** /**
* @file * @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\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\Field\PluginSettingsInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Field UI display overview form. * Edit form for the EntityViewDisplay entity type.
*/ */
class DisplayOverview extends DisplayOverviewBase { class EntityViewDisplayEditForm extends EntityDisplayFormBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected $displayContext = 'view'; 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} * {@inheritdoc}
*/ */
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('entity.manager'),
$container->get('plugin.manager.field.field_type'), $container->get('plugin.manager.field.field_type'),
$container->get('plugin.manager.field.formatter'), $container->get('plugin.manager.field.formatter')
$container->get('module_handler'), );
$container->get('config.factory')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'field_ui_display_overview_form';
}
/**
* {@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);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
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_row = parent::buildFieldRow($field_definition, $entity_display, $form, $form_state); $field_row = parent::buildFieldRow($field_definition, $form, $form_state);
$field_name = $field_definition->getName(); $field_name = $field_definition->getName();
$display_options = $entity_display->getComponent($field_name); $display_options = $this->entity->getComponent($field_name);
// Insert the label column. // Insert the label column.
$label = array( $label = array(
...@@ -108,7 +58,7 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent ...@@ -108,7 +58,7 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent
// Update the (invisible) title of the 'plugin' column. // Update the (invisible) title of the 'plugin' column.
$field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $field_definition->getLabel())); $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(); $plugin_type_info = $plugin->getPluginDefinition();
$field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Format settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>'; $field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Format settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>';
} }
...@@ -119,8 +69,8 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent ...@@ -119,8 +69,8 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, Ent
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function buildExtraFieldRow($field_id, $extra_field, EntityDisplayInterface $entity_display) { protected function buildExtraFieldRow($field_id, $extra_field) {
$extra_field_row = parent::buildExtraFieldRow($field_id, $extra_field, $entity_display); $extra_field_row = parent::buildExtraFieldRow($field_id, $extra_field);
// Insert an empty placeholder for the label column. // Insert an empty placeholder for the label column.
$label = array( $label = array(
...@@ -137,8 +87,8 @@ protected function buildExtraFieldRow($field_id, $extra_field, EntityDisplayInte ...@@ -137,8 +87,8 @@ protected function buildExtraFieldRow($field_id, $extra_field, EntityDisplayInte
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function getEntityDisplay($mode) { protected function getEntityDisplay($entity_type_id, $bundle, $mode) {
return entity_get_display($this->entity_type, $this->bundle, $mode); return entity_get_display($entity_type_id, $bundle, $mode);
} }
/** /**
...@@ -150,7 +100,7 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config ...@@ -150,7 +100,7 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config
if ($configuration && $configuration['type'] != 'hidden') { if ($configuration && $configuration['type'] != 'hidden') {
$plugin = $this->pluginManager->getInstance(array( $plugin = $this->pluginManager->getInstance(array(
'field_definition' => $field_definition, 'field_definition' => $field_definition,
'view_mode' => $this->mode, 'view_mode' => $this->entity->mode,
'configuration' => $configuration 'configuration' => $configuration
)); ));
} }
...@@ -158,13 +108,6 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config ...@@ -158,13 +108,6 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config
return $plugin; return $plugin;
} }
/**
* {@inheritdoc}
*/
protected function getPluginOptions(FieldDefinitionInterface $field_definition) {
return parent::getPluginOptions($field_definition) + array('hidden' => '- ' . $this->t('Hidden') . ' -');
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -176,14 +119,7 @@ protected function getDefaultPlugin($field_type) { ...@@ -176,14 +119,7 @@ protected function getDefaultPlugin($field_type) {
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function getDisplayModes() { protected function getDisplayModes() {
return $this->entityManager->getViewModes($this->entity_type); return $this->entityManager->getViewModes($this->entity->targetEntityType);
}
/**
* {@inheritdoc}