diff --git a/core/modules/outside_in/outside_in.module b/core/modules/outside_in/outside_in.module index a7fab7b..9eba1ce 100644 --- a/core/modules/outside_in/outside_in.module +++ b/core/modules/outside_in/outside_in.module @@ -10,6 +10,7 @@ use Drupal\outside_in\Block\BlockEntityOffCanvasForm; use Drupal\outside_in\Form\SystemBrandingOffCanvasForm; use Drupal\outside_in\Form\SystemMenuOffCanvasForm; +use Drupal\outside_in\Form\SearchBlockOffCanvasForm; /** * Implements hook_help(). @@ -133,6 +134,10 @@ function outside_in_block_alter(&$definitions) { $definitions['system_branding_block']['forms']['offcanvas'] = SystemBrandingOffCanvasForm::class; } + if (!empty($definitions['search_form_block'])) { + $definitions['search_form_block']['forms']['offcanvas'] = SearchBlockOffCanvasForm::class; + } + // Since menu blocks use derivatives, check the definition ID instead of // relying on the plugin ID. foreach ($definitions as &$definition) { diff --git a/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php b/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php index 0fec45c..e674d73 100644 --- a/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php +++ b/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php @@ -7,6 +7,7 @@ use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginWithFormsInterface; +use Drupal\Core\Render\Element\Form; /** * Provides form for block instance forms when used in the off-canvas tray. @@ -52,10 +53,31 @@ public function form(array $form, FormStateInterface $form_state) { // Remove the ID and region elements. unset($form['id'], $form['region'], $form['settings']['admin_label']); + // Only show the label input if the label will be shown on the page. + $form['settings']['label_display']['#weight'] = -100; + $form['settings']['label']['#states']['visible'] = [ + ':input[name="settings[label_display]"]' => ['checked' => TRUE], + ]; + + $form['settings']['label']['#process'][] = [get_class($this), 'processLabelInput']; return $form; } /** + * Element process callback for block label element. + * + * Checks to make sure the label has a value even if it was set to invisible + * on the form via javascript. + */ + public static function processLabelInput(&$element, FormStateInterface &$form_state, array &$form) { + $input = $form_state->getUserInput(); + if (isset($input['settings']['label']) && empty($input['settings']['label_display'])) { + $element['#value'] = $element['#default_value']; + } + return $element; + } + + /** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { diff --git a/core/modules/outside_in/src/Form/OffCanvasPluginFormBase.php b/core/modules/outside_in/src/Form/OffCanvasPluginFormBase.php new file mode 100644 index 0000000..54ef735 --- /dev/null +++ b/core/modules/outside_in/src/Form/OffCanvasPluginFormBase.php @@ -0,0 +1,47 @@ +plugin->buildConfigurationForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + $this->plugin->submitConfigurationForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + $this->plugin->validateConfigurationForm($form, $form_state); + } + +} + diff --git a/core/modules/outside_in/src/Form/SearchBlockOffCanvasForm.php b/core/modules/outside_in/src/Form/SearchBlockOffCanvasForm.php new file mode 100644 index 0000000..033a8bd --- /dev/null +++ b/core/modules/outside_in/src/Form/SearchBlockOffCanvasForm.php @@ -0,0 +1,61 @@ +redirectDestination = $redirect_destination; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('redirect.destination') + ); + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + $form = parent::buildConfigurationForm($form, $form_state); + $form['search_config_link'] = [ + '#type' => 'link', + '#title' => $this->t('Site search configuration'), + '#url' => Url::fromRoute('entity.search_page.collection', [], ['query' => ['destination' => $this->redirectDestination->get()]]), + '#weight' => 110, + ]; + return $form; + } + +} diff --git a/core/modules/outside_in/src/Form/SystemBrandingOffCanvasForm.php b/core/modules/outside_in/src/Form/SystemBrandingOffCanvasForm.php index 063041d..b611905 100644 --- a/core/modules/outside_in/src/Form/SystemBrandingOffCanvasForm.php +++ b/core/modules/outside_in/src/Form/SystemBrandingOffCanvasForm.php @@ -13,14 +13,7 @@ * * @see outside_in_block_alter() */ -class SystemBrandingOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface { - - /** - * The block plugin. - * - * @var \Drupal\Core\Block\BlockPluginInterface - */ - protected $plugin; +class SystemBrandingOffCanvasForm extends OffCanvasPluginFormBase implements ContainerInjectionInterface { /** * The config factory. @@ -52,7 +45,7 @@ public static function create(ContainerInterface $container) { * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form = $this->plugin->buildConfigurationForm($form, $form_state); + $form = parent::buildConfigurationForm($form, $form_state); $form['block_branding']['#type'] = 'details'; $form['block_branding']['#weight'] = 10; @@ -85,20 +78,13 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->plugin->validateConfigurationForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { $site_info = $form_state->getValue('site_information'); $this->configFactory->getEditable('system.site') ->set('name', $site_info['site_name']) ->set('slogan', $site_info['site_slogan']) ->save(); - $this->plugin->submitConfigurationForm($form, $form_state); + parent::submitConfigurationForm($form, $form_state); } } diff --git a/core/modules/outside_in/src/Form/SystemMenuOffCanvasForm.php b/core/modules/outside_in/src/Form/SystemMenuOffCanvasForm.php index 34731f8..6fb6acf 100644 --- a/core/modules/outside_in/src/Form/SystemMenuOffCanvasForm.php +++ b/core/modules/outside_in/src/Form/SystemMenuOffCanvasForm.php @@ -21,19 +21,12 @@ * * @see outside_in_block_alter() */ -class SystemMenuOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface { +class SystemMenuOffCanvasForm extends OffCanvasPluginFormBase implements ContainerInjectionInterface { use StringTranslationTrait; use RedirectDestinationTrait; /** - * The plugin. - * - * @var \Drupal\Core\Block\BlockPluginInterface - */ - protected $plugin; - - /** * @var \Drupal\system\MenuInterface */ protected $entity; @@ -76,9 +69,10 @@ public static function create(ContainerInterface $container) { * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form = $this->plugin->buildConfigurationForm([], $form_state); + $form = parent::buildConfigurationForm($form, $form_state); // Move the menu levels section to the bottom. $form['menu_levels']['#weight'] = 100; + $form['menu_levels']['#open'] = FALSE; $form['entity_form'] = [ '#type' => 'details', @@ -118,7 +112,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta * {@inheritdoc} */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->plugin->validateConfigurationForm($form, $form_state); + parent::validateConfigurationForm($form, $form_state); $this->getEntityForm($this->entity)->validateForm($form, $form_state); } @@ -126,7 +120,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->plugin->submitConfigurationForm($form, $form_state); + parent::submitConfigurationForm($form, $form_state); $this->getEntityForm($this->entity)->submitForm($form, $form_state); $this->entity->save(); }