Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / outside_in / src / Block / BlockEntityOffCanvasForm.php
1 <?php
2
3 namespace Drupal\outside_in\Block;
4
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;
10
11 /**
12  * Provides form for block instance forms when used in the off-canvas dialog.
13  *
14  * This form removes advanced sections of regular block form such as the
15  * visibility settings, machine ID and region.
16  */
17 class BlockEntityOffCanvasForm extends BlockForm {
18
19   /**
20    * Provides a title callback to get the block's admin label.
21    *
22    * @param \Drupal\block\BlockInterface $block
23    *   The block entity.
24    *
25    * @return \Drupal\Core\StringTranslation\TranslatableMarkup
26    *   The title.
27    */
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']]);
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function form(array $form, FormStateInterface $form_state) {
38     $form = parent::form($form, $form_state);
39
40     // Create link to full block form.
41     $query = [];
42     if ($destination = $this->getRequest()->query->get('destination')) {
43       $query['destination'] = $destination;
44     }
45     $form['advanced_link'] = [
46       '#type' => 'link',
47       '#title' => $this->t('Advanced block options'),
48       '#url' => $this->entity->toUrl('edit-form', ['query' => $query]),
49       '#weight' => 1000,
50     ];
51
52     // Remove the ID and region elements.
53     unset($form['id'], $form['region'], $form['settings']['admin_label']);
54
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],
60       ];
61
62       // Relabel to "Block title" because on the front-end this may be confused
63       // with page title.
64       $form['settings']['label']['#title'] = $this->t("Block title");
65       $form['settings']['label_display']['#title'] = $this->t("Display block title");
66     }
67     return $form;
68   }
69
70   /**
71    * {@inheritdoc}
72    */
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;
77     return $actions;
78   }
79
80   /**
81    * {@inheritdoc}
82    */
83   protected function buildVisibilityInterface(array $form, FormStateInterface $form_state) {
84     // Do not display the visibility.
85     return [];
86   }
87
88   /**
89    * {@inheritdoc}
90    */
91   protected function validateVisibility(array $form, FormStateInterface $form_state) {
92     // Intentionally empty.
93   }
94
95   /**
96    * {@inheritdoc}
97    */
98   protected function submitVisibility(array $form, FormStateInterface $form_state) {
99     // Intentionally empty.
100   }
101
102   /**
103    * {@inheritdoc}
104    */
105   protected function getPluginForm(BlockPluginInterface $block) {
106     if ($block instanceof PluginWithFormsInterface) {
107       return $this->pluginFormFactory->createInstance($block, 'off_canvas', 'configure');
108     }
109     return $block;
110   }
111
112 }