From b825f8e2e56da8920f737aacadc09fb7838cae3f Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Wed, 27 Mar 2024 15:44:05 +0000 Subject: [PATCH] Issue #2651418 by vasike, DieterHolvoet, smustgrave, Xano, rpayanm, quietone, alexpott, larowlan, catch, lauriii: Non-array values for #ajax (cherry picked from commit fe3aa496f7ee4e16d4482cb31450fcffd5dd3c71) --- .../Plugin/EntityReferenceSelection/DefaultSelection.php | 6 ++++++ .../Field/Plugin/Field/FieldType/EntityReferenceItem.php | 6 +++++- .../src/Plugin/EntityReferenceSelection/UserSelection.php | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php index 9a8c1012c8d9..415fe880c7fc 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 2a58bb7585d6..782ecba82e9e 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 b3a616c3dc2d..d9a9f54fddfa 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'], -- GitLab