diff --git a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php index 41c7c70..68e0f35 100644 --- a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php +++ b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php @@ -41,8 +41,9 @@ public function isNegated() { * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - // @todo Do not abuse context mappings to hold context objects. - $contexts = $form_state->get('gathered_contexts') ?: []; + $temporary = $form_state->getTemporary(); + $contexts = isset($temporary['gathered_contexts']) ? $temporary['gathered_contexts'] : []; + $form['context_mapping'] = $this->addContextAssignmentElement($contexts); $form['context_mapping']['#weight'] = -100; $form['negate'] = array( diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index c0cf9d6..2755b39 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -103,7 +103,9 @@ public function form(array $form, FormStateInterface $form_state) { // Store the gathered contexts in the form state for other objects to use // during form building. - $form_state->set('gathered_contexts', $this->dispatcher->dispatch(BlockEvents::ADMINISTRATIVE_CONTEXT, new BlockContextEvent())->getContexts()); + $temporary = $form_state->getTemporary(); + $temporary['gathered_contexts'] = $this->dispatcher->dispatch(BlockEvents::ADMINISTRATIVE_CONTEXT, new BlockContextEvent())->getContexts(); + $form_state->setTemporary($temporary); $form['#tree'] = TRUE; $form['settings'] = $entity->getPlugin()->buildConfigurationForm(array(), $form_state); @@ -165,8 +167,6 @@ public function form(array $form, FormStateInterface $form_state) { drupal_get_path('module', 'block') . '/css/block.admin.css', ); - // Clear out the gathered contexts. - $form_state->set('gathered_contexts', []); return $form; } diff --git a/core/modules/system/tests/modules/condition_test/src/FormController.php b/core/modules/system/tests/modules/condition_test/src/FormController.php index e81127d..1f13755 100644 --- a/core/modules/system/tests/modules/condition_test/src/FormController.php +++ b/core/modules/system/tests/modules/condition_test/src/FormController.php @@ -42,9 +42,6 @@ public function __construct() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { - // Clear out the gathered contexts. - $form_state->set('gathered_contexts', []); - $form = $this->condition->buildConfigurationForm($form, $form_state); $form['actions']['submit'] = array( '#type' => 'submit',