function EntityReferenceItem::fieldSettingsForm
Same name in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::fieldSettingsForm()
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::fieldSettingsForm()
- 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::fieldSettingsForm()
1 method overrides EntityReferenceItem::fieldSettingsForm()
- FileItem::fieldSettingsForm in core/
modules/ file/ src/ Plugin/ Field/ FieldType/ FileItem.php
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ EntityReferenceItem.php, line 442
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' => [
[
static::class,
'fieldSettingsAjaxProcess',
],
],
'#element_validate' => [
[
static::class,
'fieldSettingsFormValidate',
],
],
];
$form['handler'] = [
'#type' => 'details',
'#title' => $this->t('Reference type'),
'#open' => TRUE,
'#tree' => TRUE,
'#process' => [
[
static::class,
'formProcessMergeParent',
],
],
];
$form['handler']['handler'] = [
'#type' => 'select',
'#title' => $this->t('Reference method'),
'#options' => $handlers_options,
'#default_value' => $field->getSetting('handler'),
'#required' => TRUE,
// Use a form process callback to build #ajax property properly and also
// to avoid code duplication.
// @see \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::fieldSettingsAjaxProcess()
'#ajax' => TRUE,
'#limit_validation_errors' => [],
];
$form['handler']['handler_submit'] = [
'#type' => 'submit',
'#name' => 'handler_settings_submit',
'#value' => $this->t('Change handler'),
'#limit_validation_errors' => [],
'#attributes' => [
'class' => [
'js-hide',
],
],
'#submit' => [
[
static::class,
'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.