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.
17 class EntityViewDisplayEditForm extends EntityDisplayFormBase {
22 protected $displayContext = 'view';
27 public static function create(ContainerInterface $container) {
29 $container->get('plugin.manager.field.field_type'),
30 $container->get('plugin.manager.field.formatter')
37 protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
38 $field_row = parent::buildFieldRow($field_definition, $form, $form_state);
40 $field_name = $field_definition->getName();
41 $display_options = $this->entity->getComponent($field_name);
43 // Insert the label column.
47 '#title' => $this->t('Label display for @title', ['@title' => $field_definition->getLabel()]),
48 '#title_display' => 'invisible',
49 '#options' => $this->getFieldLabelOptions(),
50 '#default_value' => $display_options ? $display_options['label'] : 'above',
54 $label_position = array_search('plugin', array_keys($field_row));
55 $field_row = array_slice($field_row, 0, $label_position, TRUE) + $label + array_slice($field_row, $label_position, count($field_row) - 1, TRUE);
57 // Update the (invisible) title of the 'plugin' column.
58 $field_row['plugin']['#title'] = $this->t('Formatter for @title', ['@title' => $field_definition->getLabel()]);
59 if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $this->entity->getRenderer($field_name))) {
60 $plugin_type_info = $plugin->getPluginDefinition();
61 $field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Format settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>';
70 protected function buildExtraFieldRow($field_id, $extra_field) {
71 $extra_field_row = parent::buildExtraFieldRow($field_id, $extra_field);
73 // Insert an empty placeholder for the label column.
79 $label_position = array_search('plugin', array_keys($extra_field_row));
80 $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);
82 return $extra_field_row;
88 protected function getEntityDisplay($entity_type_id, $bundle, $mode) {
89 return entity_get_display($entity_type_id, $bundle, $mode);
95 protected function getDefaultPlugin($field_type) {
96 return isset($this->fieldTypes[$field_type]['default_formatter']) ? $this->fieldTypes[$field_type]['default_formatter'] : NULL;
102 protected function getDisplayModes() {
103 return $this->entityManager->getViewModes($this->entity->getTargetEntityTypeId());
109 protected function getDisplayModeOptions() {
110 return $this->entityManager->getViewModeOptions($this->entity->getTargetEntityTypeId());
116 protected function getDisplayModesLink() {
119 '#title' => t('Manage view modes'),
120 '#url' => Url::fromRoute('entity.entity_view_mode.collection'),
127 protected function getTableHeader() {
134 ['data' => $this->t('Format'), 'colspan' => 3],
141 protected function getOverviewUrl($mode) {
142 $entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId());
143 return Url::fromRoute('entity.entity_view_display.' . $this->entity->getTargetEntityTypeId() . '.view_mode', [
144 'view_mode_name' => $mode,
145 ] + FieldUI::getRouteBundleParameter($entity_type, $this->entity->getTargetBundle()));
149 * Returns an array of visibility options for field labels.
152 * An array of visibility options.
154 protected function getFieldLabelOptions() {
156 'above' => $this->t('Above'),
157 'inline' => $this->t('Inline'),
158 'hidden' => '- ' . $this->t('Hidden') . ' -',
159 'visually_hidden' => '- ' . $this->t('Visually Hidden') . ' -',
166 protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
168 // Invoke hook_field_formatter_third_party_settings_form(), keying resulting
169 // subforms by module name.
170 foreach ($this->moduleHandler->getImplementations('field_formatter_third_party_settings_form') as $module) {
171 $settings_form[$module] = $this->moduleHandler->invoke($module, 'field_formatter_third_party_settings_form', [
174 $this->entity->getMode(),
179 return $settings_form;
185 protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition) {
187 'formatter' => $plugin,
188 'field_definition' => $field_definition,
189 'view_mode' => $this->entity->getMode(),
191 $this->moduleHandler->alter('field_formatter_settings_summary', $summary, $context);