function EntityReferenceItem::fieldSettingsForm
Overrides FieldItemBase::fieldSettingsForm
1 method overrides EntityReferenceItem::fieldSettingsForm()
- FileItem::fieldSettingsForm in core/modules/ file/ src/ Plugin/ Field/ FieldType/ FileItem.php 
- Returns a form for the field-level settings.
File
- 
              core/lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ EntityReferenceItem.php, line 372 
Class
- EntityReferenceItem
- Defines the 'entity_reference' entity field type.
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeCode
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
  $field = $form_state->getFormObject()
    ->getEntity();
  // Get all selection plugins for this entity type.
  $selection_plugins = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionGroups($this->getSetting('target_type'));
  $handlers_options = [];
  foreach (array_keys($selection_plugins) as $selection_group_id) {
    // We only display base plugins (e.g. 'default', 'views', ...) and not
    // entity type specific plugins (e.g. 'default:node', 'default:user',
    // ...).
    if (array_key_exists($selection_group_id, $selection_plugins[$selection_group_id])) {
      $handlers_options[$selection_group_id] = Html::escape($selection_plugins[$selection_group_id][$selection_group_id]['label']);
    }
    elseif (array_key_exists($selection_group_id . ':' . $this->getSetting('target_type'), $selection_plugins[$selection_group_id])) {
      $selection_group_plugin = $selection_group_id . ':' . $this->getSetting('target_type');
      $handlers_options[$selection_group_plugin] = Html::escape($selection_plugins[$selection_group_id][$selection_group_plugin]['base_plugin_label']);
    }
  }
  $form = [
    '#type' => 'container',
    '#process' => [
      [
        get_class($this),
        'fieldSettingsAjaxProcess',
      ],
    ],
    '#element_validate' => [
      [
        get_class($this),
        'fieldSettingsFormValidate',
      ],
    ],
  ];
  $form['handler'] = [
    '#type' => 'details',
    '#title' => t('Reference type'),
    '#open' => TRUE,
    '#tree' => TRUE,
    '#process' => [
      [
        get_class($this),
        'formProcessMergeParent',
      ],
    ],
  ];
  $form['handler']['handler'] = [
    '#type' => 'select',
    '#title' => t('Reference method'),
    '#options' => $handlers_options,
    '#default_value' => $field->getSetting('handler'),
    '#required' => TRUE,
    '#ajax' => TRUE,
    '#limit_validation_errors' => [],
  ];
  $form['handler']['handler_submit'] = [
    '#type' => 'submit',
    '#value' => t('Change handler'),
    '#limit_validation_errors' => [],
    '#attributes' => [
      'class' => [
        'js-hide',
      ],
    ],
    '#submit' => [
      [
        get_class($this),
        'settingsAjaxSubmit',
      ],
    ],
  ];
  $form['handler']['handler_settings'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'entity_reference-settings',
      ],
    ],
  ];
  $handler = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionHandler($field);
  $form['handler']['handler_settings'] += $handler->buildConfigurationForm([], $form_state);
  return $form;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
