You are here

public function DashboardBlockFormBase::buildForm in Draggable dashboard 8.2

Parameters

array $form:

\Drupal\Core\Form\FormStateInterface $form_state:

Return value

array

Throws

\Drupal\Component\Plugin\Exception\PluginException

Overrides FormInterface::buildForm

2 calls to DashboardBlockFormBase::buildForm()
DashboardAssignBlockForm::buildForm in src/Form/DashboardAssignBlockForm.php
Builds assign block form.
DashboardConfigureBlockForm::buildForm in src/Form/DashboardConfigureBlockForm.php
Form constructor.
2 methods override DashboardBlockFormBase::buildForm()
DashboardAssignBlockForm::buildForm in src/Form/DashboardAssignBlockForm.php
Builds assign block form.
DashboardConfigureBlockForm::buildForm in src/Form/DashboardConfigureBlockForm.php
Form constructor.

File

src/Form/DashboardBlockFormBase.php, line 88

Class

DashboardBlockFormBase
Class DashboardBlockFormBase

Namespace

Drupal\draggable_dashboard\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\Core\Block\BlockPluginInterface $block_instance */
  $block_instance = $this->blockManager
    ->createInstance($this->block['settings']['id'], $this->block['settings']);
  $form_state
    ->setTemporaryValue('gathered_contexts', $this->contextRepository
    ->getAvailableContexts());
  $form['settings'] = [
    '#tree' => TRUE,
  ];
  $subform_state = SubformState::createForSubform($form['settings'], $form, $form_state);
  $form['settings'] = $this
    ->getPluginForm($block_instance)
    ->buildConfigurationForm($form['settings'], $subform_state);
  if (empty($this->block['settings']['provider'])) {

    // If creating a new block, calculate a safe default machine name.
    $form['id'] = [
      '#type' => 'machine_name',
      '#maxlength' => 64,
      '#description' => $this
        ->t('A unique name for this block instance. Must be alpha-numeric and underscore separated.'),
      '#machine_name' => [
        'exists' => [
          $this,
          'blockIdExists',
        ],
        'replace_pattern' => '[^a-z0-9_]+',
        'source' => [
          'settings',
          'label',
        ],
      ],
      '#required' => TRUE,
      '#weight' => -10,
    ];
    if (empty($form['settings']['label']) || !empty($form['settings']['label']['#access']) && !$form['settings']['label']['#access'] && !empty($form['settings']['views_label'])) {
      $form['id']['#machine_name']['source'] = [
        'settings',
        'views_label',
      ];
    }
  }
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
  ];
  $form['actions']['cancel'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Cancel'),
    '#attributes' => [
      'class' => [
        'button',
      ],
    ],
    '#url' => $this->dashboard
      ->toUrl('edit-form'),
  ];
  return $form;
}