3 namespace Drupal\field_ui\Form;
5 use Drupal\Core\Field\FieldDefinitionInterface;
6 use Drupal\Core\Field\PluginSettingsInterface;
7 use Drupal\Core\Form\FormStateInterface;
9 use Drupal\field_ui\FieldUI;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
13 * Edit form for the EntityViewDisplay entity type.
15 class EntityViewDisplayEditForm extends EntityDisplayFormBase {
20 protected $displayContext = 'view';
25 public static function create(ContainerInterface $container) {
27 $container->get('plugin.manager.field.field_type'),
28 $container->get('plugin.manager.field.formatter')
35 protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
36 $field_row = parent::buildFieldRow($field_definition, $form, $form_state);
38 $field_name = $field_definition->getName();
39 $display_options = $this->entity->getComponent($field_name);
41 // Insert the label column.
45 '#title' => $this->t('Label display for @title', ['@title' => $field_definition->getLabel()]),
46 '#title_display' => 'invisible',
47 '#options' => $this->getFieldLabelOptions(),
48 '#default_value' => $display_options ? $display_options['label'] : 'above',
52 $label_position = array_search('plugin', array_keys($field_row));
53 $field_row = array_slice($field_row, 0, $label_position, TRUE) + $label + array_slice($field_row, $label_position, count($field_row) - 1, TRUE);
55 // Update the (invisible) title of the 'plugin' column.
56 $field_row['plugin']['#title'] = $this->t('Formatter for @title', ['@title' => $field_definition->getLabel()]);
57 if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $this->entity->getRenderer($field_name))) {
58 $plugin_type_info = $plugin->getPluginDefinition();
59 $field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Format settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>';
68 protected function buildExtraFieldRow($field_id, $extra_field) {
69 $extra_field_row = parent::buildExtraFieldRow($field_id, $extra_field);
71 // Insert an empty placeholder for the label column.
77 $label_position = array_search('plugin', array_keys($extra_field_row));
78 $extra_field_row = array_slice($extra_field_row, 0, $label_position, TRUE) + $label + array_slice($extra_field_row, $label_position, count($extra_field_row) - 1, TRUE);
80 return $extra_field_row;
86 protected function getEntityDisplay($entity_type_id, $bundle, $mode) {
87 return entity_get_display($entity_type_id, $bundle, $mode);
93 protected function getDefaultPlugin($field_type) {
94 return isset($this->fieldTypes[$field_type]['default_formatter']) ? $this->fieldTypes[$field_type]['default_formatter'] : NULL;
100 protected function getDisplayModes() {
101 return $this->entityManager->getViewModes($this->entity->getTargetEntityTypeId());
107 protected function getDisplayModeOptions() {
108 return $this->entityManager->getViewModeOptions($this->entity->getTargetEntityTypeId());
114 protected function getDisplayModesLink() {
118 '#title' => t('Manage view modes'),
119 '#url' => Url::fromRoute('entity.entity_view_mode.collection'),
126 protected function getTableHeader() {
133 ['data' => $this->t('Format'), 'colspan' => 3],
140 protected function getOverviewUrl($mode) {
141 $entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId());
142 return Url::fromRoute('entity.entity_view_display.' . $this->entity->getTargetEntityTypeId() . '.view_mode', [
143 'view_mode_name' => $mode,
144 ] + FieldUI::getRouteBundleParameter($entity_type, $this->entity->getTargetBundle()));
148 * Returns an array of visibility options for field labels.
151 * An array of visibility options.
153 protected function getFieldLabelOptions() {
155 'above' => $this->t('Above'),
156 'inline' => $this->t('Inline'),
157 'hidden' => '- ' . $this->t('Hidden') . ' -',
158 'visually_hidden' => '- ' . $this->t('Visually Hidden') . ' -',
165 protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
167 // Invoke hook_field_formatter_third_party_settings_form(), keying resulting
168 // subforms by module name.
169 foreach ($this->moduleHandler->getImplementations('field_formatter_third_party_settings_form') as $module) {
170 $settings_form[$module] = $this->moduleHandler->invoke($module, 'field_formatter_third_party_settings_form', [
173 $this->entity->getMode(),
178 return $settings_form;
184 protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition) {
186 'formatter' => $plugin,
187 'field_definition' => $field_definition,
188 'view_mode' => $this->entity->getMode(),
190 $this->moduleHandler->alter('field_formatter_settings_summary', $summary, $context);