diff --git a/core/lib/Drupal/Core/Block/BlockBase.php b/core/lib/Drupal/Core/Block/BlockBase.php index 66f6cb3..58f79a3 100644 --- a/core/lib/Drupal/Core/Block/BlockBase.php +++ b/core/lib/Drupal/Core/Block/BlockBase.php @@ -163,8 +163,6 @@ protected function blockAccess(AccountInterface $account) { */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $definition = $this->getPluginDefinition(); - $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: []; - $form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts); $form['provider'] = array( '#type' => 'value', '#value' => $definition['provider'], @@ -233,6 +231,9 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form['cache']['contexts']['#description'] .= ' ' . t('This block is always varied by the following contexts: %required-context-list.', array('%required-context-list' => $required_context_list)); } + // Add context form elements. + $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: []; + $form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts); // Add plugin-specific settings for this block type. $form += $this->blockForm($form, $form_state); return $form; diff --git a/core/modules/block/src/Tests/BlockInterfaceTest.php b/core/modules/block/src/Tests/BlockInterfaceTest.php index cb17bf7..716f6db 100644 --- a/core/modules/block/src/Tests/BlockInterfaceTest.php +++ b/core/modules/block/src/Tests/BlockInterfaceTest.php @@ -67,7 +67,6 @@ public function testBlockInterface() { $contexts = \Drupal::service("cache_contexts")->getLabels(); unset($contexts['cache_context.theme']); $expected_form = array( - 'context_mapping' => array(), 'provider' => array( '#type' => 'value', '#value' => 'block_test', @@ -113,6 +112,7 @@ public function testBlockInterface() { ), ), ), + 'context_mapping' => array(), 'display_message' => array( '#type' => 'textfield', '#title' => t('Display message'),