diff --git a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php index 5aed43f..98d87dd 100644 --- a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php +++ b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php @@ -98,6 +98,8 @@ public function isNegated() { * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + // Retrieve the globally available contexts. + $contexts = $this->getContextRepository()->getAvailableContexts(); // Getting contexts from the form state is deprecated, as it means this // implementation of // \Drupal\Core\Plugin\PluginFormInterface::buildConfigurationForm() is not @@ -105,13 +107,13 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta // \Drupal\block\BlockForm. // @todo Remove this before Drupal 9.0.0. if ($form_state->hasTemporaryValue('gathered_contexts')) { - $contexts = $form_state->getTemporaryValue('gathered_contexts'); + $contexts = array_merge($contexts, $form_state->getTemporaryValue('gathered_contexts')); } - else { - $contexts = $this->getContextRepository()->getAvailableContexts(); + foreach ($contexts as $context_id => $context) { + $this->setContext($context_id, $context); } - $form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts); + $form['context_mapping'] = $this->addContextAssignmentElement($this, $this->getContexts()); $form['negate'] = array( '#type' => 'checkbox', '#title' => $this->t('Negate the condition'), diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextRepositoryInterface.php b/core/lib/Drupal/Core/Plugin/Context/ContextRepositoryInterface.php index 6d7d609..a05fdaf 100644 --- a/core/lib/Drupal/Core/Plugin/Context/ContextRepositoryInterface.php +++ b/core/lib/Drupal/Core/Plugin/Context/ContextRepositoryInterface.php @@ -39,7 +39,7 @@ public function getRuntimeContexts(array $context_ids); * Gets all available contexts for the purposes of configuration. * * @return \Drupal\Core\Plugin\Context\ContextInterface[] - * All available contexts. + * All available contexts, keyed by context ID. */ public function getAvailableContexts();