diff --git a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php index 9a8c1012c8d90e191c6f834e669d478d5a01078f..415fe880c7fcebb093c1421e75c07759abed880c 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php +++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php @@ -183,6 +183,9 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#size' => 6, '#multiple' => TRUE, '#element_validate' => [[static::class, 'elementValidateFilter']], + // 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' => [], ]; @@ -232,6 +235,9 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#type' => 'select', '#title' => $this->t('Sort by'), '#options' => $fields, + // 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, '#empty_value' => '_none', '#sort_options' => TRUE, diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index 2a58bb7585d6d32a3e7aefab60ec84b2859fd1c6..782ecba82e9e2ac97434eb3d09108f0be9f07aab 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -2,11 +2,11 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Core\Entity\ContentEntityStorageInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\TypedData\EntityDataDefinition; @@ -477,6 +477,9 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { '#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' => [], ]; @@ -703,6 +706,7 @@ public static function fieldSettingsAjaxProcess($form, FormStateInterface $form_ * @see static::fieldSettingsAjaxProcess() */ public static function fieldSettingsAjaxProcessElement(&$element, $main_form) { + // Elements are marked as TRUE ('#ajax' => TRUE,), so not empty. if (!empty($element['#ajax'])) { $element['#ajax'] = [ 'trigger_as' => ['name' => 'handler_settings_submit'], diff --git a/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php b/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php index b3a616c3dc2d67fe262d16c6296ab7aa0eef6b81..d9a9f54fddfafc0fefb4a14e895479d12d0d8cbc 100644 --- a/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php +++ b/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php @@ -117,6 +117,9 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '_none' => $this->t('- None -'), 'role' => $this->t('User role'), ], + // 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' => [], '#default_value' => $configuration['filter']['type'],