diff --git a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php index fce2937..4d268dc 100644 --- a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php +++ b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php @@ -2,6 +2,7 @@ namespace Drupal\views\Plugin\views\wizard; +use Drupal\block\BlockInterface; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\UrlGeneratorTrait; @@ -365,6 +366,37 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'textfield', '#maxlength' => 255, ); + $form['displays']['block']['options']['placement'] = [ + '#type' => 'fieldset', + '#title' => $this->t('Block placement'), + '#attributes' => ['class' => ['container-inline', 'fieldset-no-legend']], + ]; + $theme_options = array(); + foreach (\Drupal::service('theme_handler')->listInfo() as $theme_name => $theme_info) { + if (!empty($theme_info->status)) { + $theme_options[$theme_name] = $theme_info->info['name']; + } + } + $theme = key($theme_options); + $form['displays']['block']['options']['placement']['theme'] = [ + '#type' => 'select', + '#options' => $theme_options, + '#default_value' => $theme, + '#title' => $this->t('Theme'), + '#ajax' => [ + 'callback' => [$this, 'themeSwitch'], + 'wrapper' => 'edit-block-region-wrapper', + ], + ]; + $form['displays']['block']['options']['placement']['region'] = array( + '#type' => 'select', + '#title' => $this->t('Region'), + '#description' => $this->t('Select the region where this block should be displayed.'), + '#empty_value' => BlockInterface::BLOCK_REGION_NONE, + '#options' => system_region_list($theme, REGIONS_VISIBLE), + '#prefix' => '
', + '#suffix' => '
', + ); $form['displays']['block']['options']['style'] = array( '#type' => 'fieldset', '#title' => $this->t('Block display settings'), @@ -441,6 +473,14 @@ public function buildForm(array $form, FormStateInterface $form_state) { } /** + * Handles switching the available regions based on the selected theme. + */ + public function themeSwitch($form, FormStateInterface $form_state) { + $form['displays']['block']['options']['placement']['region']['#options'] = system_region_list($form_state->getValue(['block', 'placement', 'theme']), REGIONS_VISIBLE); + return $form['displays']['block']['options']['placement']['region']; + } + + /** * Gets the current value of a #select element, from within a form constructor function. * * This function is intended for use in highly dynamic forms (in particular the