Version 1
[yaffs-website] / web / core / modules / field_ui / src / Form / EntityFormDisplayEditForm.php
1 <?php
2
3 namespace Drupal\field_ui\Form;
4
5 use Drupal\Core\Field\FieldDefinitionInterface;
6 use Drupal\Core\Field\PluginSettingsInterface;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\Core\Url;
9 use Drupal\field_ui\FieldUI;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11
12 /**
13  * Edit form for the EntityFormDisplay entity type.
14  */
15 class EntityFormDisplayEditForm extends EntityDisplayFormBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected $displayContext = 'form';
21
22   /**
23    * {@inheritdoc}
24    */
25   public static function create(ContainerInterface $container) {
26     return new static(
27       $container->get('plugin.manager.field.field_type'),
28       $container->get('plugin.manager.field.widget')
29     );
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
36     $field_row = parent::buildFieldRow($field_definition, $form, $form_state);
37
38     $field_name = $field_definition->getName();
39
40     // Update the (invisible) title of the 'plugin' column.
41     $field_row['plugin']['#title'] = $this->t('Formatter for @title', ['@title' => $field_definition->getLabel()]);
42     if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $this->entity->getRenderer($field_name))) {
43       $plugin_type_info = $plugin->getPluginDefinition();
44       $field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Widget settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>';
45     }
46
47     return $field_row;
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   protected function getEntityDisplay($entity_type_id, $bundle, $mode) {
54     return entity_get_form_display($entity_type_id, $bundle, $mode);
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   protected function getDefaultPlugin($field_type) {
61     return isset($this->fieldTypes[$field_type]['default_widget']) ? $this->fieldTypes[$field_type]['default_widget'] : NULL;
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   protected function getDisplayModes() {
68     return $this->entityManager->getFormModes($this->entity->getTargetEntityTypeId());
69   }
70
71   /**
72    * {@inheritdoc}
73    */
74   protected function getDisplayModeOptions() {
75     return $this->entityManager->getFormModeOptions($this->entity->getTargetEntityTypeId());
76   }
77
78   /**
79    * {@inheritdoc}
80    */
81   protected function getDisplayModesLink() {
82     return [
83       '#type' => 'link',
84       '#title' => t('Manage form modes'),
85       '#url' => Url::fromRoute('entity.entity_form_mode.collection'),
86     ];
87   }
88
89   /**
90    * {@inheritdoc}
91    */
92   protected function getTableHeader() {
93     return [
94       $this->t('Field'),
95       $this->t('Weight'),
96       $this->t('Parent'),
97       $this->t('Region'),
98       ['data' => $this->t('Widget'), 'colspan' => 3],
99     ];
100   }
101
102   /**
103    * {@inheritdoc}
104    */
105   protected function getOverviewUrl($mode) {
106     $entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId());
107     return Url::fromRoute('entity.entity_form_display.' . $this->entity->getTargetEntityTypeId() . '.form_mode', [
108       'form_mode_name' => $mode,
109     ] + FieldUI::getRouteBundleParameter($entity_type, $this->entity->getTargetBundle()));
110   }
111
112   /**
113    * {@inheritdoc}
114    */
115   protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
116     $settings_form = [];
117     // Invoke hook_field_widget_third_party_settings_form(), keying resulting
118     // subforms by module name.
119     foreach ($this->moduleHandler->getImplementations('field_widget_third_party_settings_form') as $module) {
120       $settings_form[$module] = $this->moduleHandler->invoke($module, 'field_widget_third_party_settings_form', [
121         $plugin,
122         $field_definition,
123         $this->entity->getMode(),
124         $form,
125         $form_state,
126       ]);
127     }
128     return $settings_form;
129   }
130
131   /**
132    * {@inheritdoc}
133    */
134   protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition) {
135     $context = [
136       'widget' => $plugin,
137       'field_definition' => $field_definition,
138       'form_mode' => $this->entity->getMode(),
139     ];
140     $this->moduleHandler->alter('field_widget_settings_summary', $summary, $context);
141   }
142
143 }