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 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']);
61 protected function actions(array $form, FormStateInterface $form_state) {
62 $actions = parent::actions($form, $form_state);
63 $actions['submit']['#value'] = $this->t('Save @block', ['@block' => $this->entity->getPlugin()->getPluginDefinition()['admin_label']]);
64 $actions['delete']['#access'] = FALSE;
71 protected function buildVisibilityInterface(array $form, FormStateInterface $form_state) {
72 // Do not display the visibility.
79 protected function validateVisibility(array $form, FormStateInterface $form_state) {
80 // Intentionally empty.
86 protected function submitVisibility(array $form, FormStateInterface $form_state) {
87 // Intentionally empty.
93 protected function getPluginForm(BlockPluginInterface $block) {
94 if ($block instanceof PluginWithFormsInterface) {
95 return $this->pluginFormFactory->createInstance($block, 'off_canvas', 'configure');