EntityFormDisplayEditForm.php 4.26 KB
Newer Older
1
2
<?php

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\Core\Link;
10
use Drupal\field_ui\FieldUI;
11
12
13
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
14
 * Edit form for the EntityFormDisplay entity type.
15
 */
16
class EntityFormDisplayEditForm extends EntityDisplayFormBase {
17

18
19
20
21
22
  /**
   * {@inheritdoc}
   */
  protected $displayContext = 'form';

23
24
25
26
27
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
28
      $container->get('plugin.manager.field.field_type'),
29
      $container->get('plugin.manager.field.widget')
30
31
32
33
34
35
    );
  }

  /**
   * {@inheritdoc}
   */
36
37
  protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
    $field_row = parent::buildFieldRow($field_definition, $form, $form_state);
38
39

    $field_name = $field_definition->getName();
40
41

    // Update the (invisible) title of the 'plugin' column.
42
    $field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $field_definition->getLabel()));
43
    if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $this->entity->getRenderer($field_name))) {
44
      $plugin_type_info = $plugin->getPluginDefinition();
45
      $field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Widget settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>';
46
47
48
49
50
51
52
53
    }

    return $field_row;
  }

  /**
   * {@inheritdoc}
   */
54
55
  protected function getEntityDisplay($entity_type_id, $bundle, $mode) {
    return entity_get_form_display($entity_type_id, $bundle, $mode);
56
57
58
59
60
61
  }

  /**
   * {@inheritdoc}
   */
  protected function getDefaultPlugin($field_type) {
62
    return isset($this->fieldTypes[$field_type]['default_widget']) ? $this->fieldTypes[$field_type]['default_widget'] : NULL;
63
64
65
66
67
68
  }

  /**
   * {@inheritdoc}
   */
  protected function getDisplayModes() {
69
    return $this->entityManager->getFormModes($this->entity->getTargetEntityTypeId());
70
71
  }

72
73
74
75
76
77
78
  /**
   * {@inheritdoc}
   */
  protected function getDisplayModeOptions() {
    return $this->entityManager->getFormModeOptions($this->entity->getTargetEntityTypeId());
  }

79
80
81
82
83
84
85
86
87
88
89
  /**
   * {@inheritdoc}
   */
  protected function getDisplayModesLink() {
    return [
      '#type' => 'link',
      '#title' => t('Manage form modes'),
      '#url' => Url::fromRoute('entity.entity_form_mode.collection'),
    ];
  }

90
  /**
91
   * {@inheritdoc}
92
93
94
   */
  protected function getTableHeader() {
    return array(
95
96
97
98
      $this->t('Field'),
      $this->t('Weight'),
      $this->t('Parent'),
      array('data' => $this->t('Widget'), 'colspan' => 3),
99
100
101
102
103
104
    );
  }

  /**
   * {@inheritdoc}
   */
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
114
  }

  /**
   * {@inheritdoc}
   */
115
  protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
116
117
118
119
120
121
122
    $settings_form = array();
    // Invoke hook_field_widget_third_party_settings_form(), keying resulting
    // subforms by module name.
    foreach ($this->moduleHandler->getImplementations('field_widget_third_party_settings_form') as $module) {
      $settings_form[$module] = $this->moduleHandler->invoke($module, 'field_widget_third_party_settings_form', array(
        $plugin,
        $field_definition,
123
        $this->entity->getMode(),
124
125
126
127
128
        $form,
        $form_state,
      ));
    }
    return $settings_form;
129
130
131
132
133
  }

  /**
   * {@inheritdoc}
   */
134
  protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition) {
135
136
    $context = array(
      '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
  }

}