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