function BlockEntitySettingTrayForm::form

Same name in other branches
  1. 9 core/modules/settings_tray/src/Block/BlockEntitySettingTrayForm.php \Drupal\settings_tray\Block\BlockEntitySettingTrayForm::form()
  2. 8.9.x core/modules/settings_tray/src/Block/BlockEntitySettingTrayForm.php \Drupal\settings_tray\Block\BlockEntitySettingTrayForm::form()
  3. 11.x core/modules/settings_tray/src/Block/BlockEntitySettingTrayForm.php \Drupal\settings_tray\Block\BlockEntitySettingTrayForm::form()

Overrides BlockForm::form

File

core/modules/settings_tray/src/Block/BlockEntitySettingTrayForm.php, line 46

Class

BlockEntitySettingTrayForm
Provides form for block instance forms when used in the off-canvas dialog.

Namespace

Drupal\settings_tray\Block

Code

public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    // Create link to full block form.
    $query = [];
    if ($destination = $this->getRequest()->query
        ->get('destination')) {
        $query['destination'] = $destination;
    }
    $form['advanced_link'] = [
        '#type' => 'link',
        '#title' => $this->t('Advanced block options'),
        '#url' => $this->entity
            ->toUrl('edit-form', [
            'query' => $query,
        ]),
        '#weight' => 1000,
    ];
    // Remove the ID and region elements.
    unset($form['id'], $form['region'], $form['settings']['admin_label']);
    if (isset($form['settings']['label_display']) && isset($form['settings']['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,
            ],
        ];
        // Relabel to "Block title" because on the front-end this may be confused
        // with page title.
        $form['settings']['label']['#title'] = $this->t("Block title");
        $form['settings']['label_display']['#title'] = $this->t("Display block title");
    }
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.