diff --git a/core/modules/block/block.routing.yml b/core/modules/block/block.routing.yml
index a2ca6e5..6e7e12d 100644
--- a/core/modules/block/block.routing.yml
+++ b/core/modules/block/block.routing.yml
@@ -24,6 +24,7 @@ block_admin_add:
pattern: '/admin/structure/block/add/{plugin_id}/{theme}'
defaults:
_content: '\Drupal\block\Controller\BlockAddController::blockAddConfigureForm'
+ theme: null
_title: 'Configure block'
requirements:
_permission: 'administer blocks'
diff --git a/core/modules/block/lib/Drupal/block/BlockFormController.php b/core/modules/block/lib/Drupal/block/BlockFormController.php
index e873888..c7fb3cd 100644
--- a/core/modules/block/lib/Drupal/block/BlockFormController.php
+++ b/core/modules/block/lib/Drupal/block/BlockFormController.php
@@ -228,6 +228,32 @@ public function form(array $form, array &$form_state) {
'#description' => $this->t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
);
+ // Theme settings.
+ if ($theme = $entity->get('theme')) {
+ $form['theme'] = array(
+ '#type' => 'value',
+ '#value' => $entity->get('theme'),
+ );
+ }
+ else {
+ $theme_options = array();
+ foreach (list_themes() as $theme_name => $theme_info) {
+ if (!empty($theme_info->status)) {
+ $theme_options[$theme_name] = $theme_info->info['name'];
+ }
+ }
+ $theme = \Drupal::config('system.theme')->get('default');
+ $form['theme'] = array(
+ '#type' => 'select',
+ '#options' => $theme_options,
+ '#title' => t('Theme'),
+ '#default_value' => $theme,
+ '#ajax' => array(
+ 'callback' => array($this, 'themeSwitch'),
+ 'wrapper' => 'edit-block-region-wrapper',
+ ),
+ );
+ }
// Region settings.
$form['region'] = array(
'#type' => 'select',
@@ -235,12 +261,22 @@ public function form(array $form, array &$form_state) {
'#description' => $this->t('Select the region where this block should be displayed.'),
'#default_value' => $entity->get('region'),
'#empty_value' => BLOCK_REGION_NONE,
- '#options' => system_region_list($entity->get('theme'), REGIONS_VISIBLE),
+ '#options' => system_region_list($theme, REGIONS_VISIBLE),
+ '#prefix' => '
',
+ '#suffix' => '
',
);
return $form;
}
/**
+ * Handles switching the available regions based on the selected theme.
+ */
+ public function themeSwitch($form, &$form_state) {
+ $form['region']['#options'] = system_region_list($form_state['values']['theme'], REGIONS_VISIBLE);
+ return $form['region'];
+ }
+
+ /**
* {@inheritdoc}
*/
protected function actions(array $form, array &$form_state) {
@@ -257,7 +293,7 @@ public function validate(array $form, array &$form_state) {
$entity = $this->entity;
if ($entity->isNew()) {
- form_set_value($form['id'], $entity->get('theme') . '.' . $form_state['values']['machine_name'], $form_state);
+ form_set_value($form['id'], $form_state['values']['theme'] . '.' . $form_state['values']['machine_name'], $form_state);
}
if (!empty($form['machine_name']['#disabled'])) {
$config_id = explode('.', $form_state['values']['machine_name']);
@@ -293,7 +329,7 @@ public function submit(array $form, array &$form_state) {
drupal_set_message($this->t('The block configuration has been saved.'));
Cache::invalidateTags(array('content' => TRUE));
- $form_state['redirect'] = array('admin/structure/block/list/' . $entity->get('theme'), array(
+ $form_state['redirect'] = array('admin/structure/block/list/' . $form_state['values']['theme'], array(
'query' => array('block-placement' => drupal_html_class($this->entity->id())),
));
}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
index 94c8b9e..13064c6 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
@@ -145,6 +145,22 @@ function testBlock() {
}
/**
+ * Tests that the block form has a theme selector when not passed via the URL.
+ */
+ public function testBlockThemeSelector() {
+ // Select the 'Powered by Drupal' block to be configured and moved.
+ $block = array();
+ $block['machine_name'] = strtolower($this->randomName(8));
+ $block['theme'] = \Drupal::config('system.theme')->get('default');
+ $block['region'] = 'header';
+
+ $this->drupalPost('admin/structure/block/add/system_powered_by_block', $block, t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'));
+ $elements = $this->xpath('//div[@id = :id]', array(':id' => drupal_html_id('block-' . $block['machine_name'])));
+ $this->assertTrue(!empty($elements), 'The block was found.');
+ }
+
+ /**
* Test block title display settings.
*/
function testHideBlockTitle() {