3 namespace Drupal\outside_in\Block;
5 use Drupal\block\BlockForm;
6 use Drupal\block\BlockInterface;
7 use Drupal\Core\Block\BlockPluginInterface;
8 use Drupal\Core\Form\FormStateInterface;
9 use Drupal\Core\Plugin\PluginWithFormsInterface;
12 * Provides form for block instance forms when used in the off-canvas dialog.
14 * This form removes advanced sections of regular block form such as the
15 * visibility settings, machine ID and region.
17 class BlockEntityOffCanvasForm extends BlockForm {
20 * Provides a title callback to get the block's admin label.
22 * @param \Drupal\block\BlockInterface $block
25 * @return \Drupal\Core\StringTranslation\TranslatableMarkup
28 public function title(BlockInterface $block) {
29 // @todo Wrap "Configure " in <span class="visually-hidden"></span> once
30 // https://www.drupal.org/node/2359901 is fixed.
31 return $this->t('Configure @block', ['@block' => $block->getPlugin()->getPluginDefinition()['admin_label']]);
37 public function form(array $form, FormStateInterface $form_state) {
38 $form = parent::form($form, $form_state);
40 // Create link to full block form.
42 if ($destination = $this->getRequest()->query->get('destination')) {
43 $query['destination'] = $destination;
45 $form['advanced_link'] = [
47 '#title' => $this->t('Advanced block options'),
48 '#url' => $this->entity->toUrl('edit-form', ['query' => $query]),
52 // Remove the ID and region elements.
53 unset($form['id'], $form['region'], $form['settings']['admin_label']);
55 if (isset($form['settings']['label_display']) && isset($form['settings']['label'])) {
56 // Only show the label input if the label will be shown on the page.
57 $form['settings']['label_display']['#weight'] = -100;
58 $form['settings']['label']['#states']['visible'] = [
59 ':input[name="settings[label_display]"]' => ['checked' => TRUE],
62 // Relabel to "Block title" because on the front-end this may be confused
64 $form['settings']['label']['#title'] = $this->t("Block title");
65 $form['settings']['label_display']['#title'] = $this->t("Display block title");
73 protected function actions(array $form, FormStateInterface $form_state) {
74 $actions = parent::actions($form, $form_state);
75 $actions['submit']['#value'] = $this->t('Save @block', ['@block' => $this->entity->getPlugin()->getPluginDefinition()['admin_label']]);
76 $actions['delete']['#access'] = FALSE;
83 protected function buildVisibilityInterface(array $form, FormStateInterface $form_state) {
84 // Do not display the visibility.
91 protected function validateVisibility(array $form, FormStateInterface $form_state) {
92 // Intentionally empty.
98 protected function submitVisibility(array $form, FormStateInterface $form_state) {
99 // Intentionally empty.
105 protected function getPluginForm(BlockPluginInterface $block) {
106 if ($block instanceof PluginWithFormsInterface) {
107 return $this->pluginFormFactory->createInstance($block, 'off_canvas', 'configure');