You are here

public function BlockVisibilityGroupDeleteForm::buildForm in Block Visibility Groups 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides EntityConfirmFormBase::buildForm

File

src/Form/BlockVisibilityGroupDeleteForm.php, line 124

Class

BlockVisibilityGroupDeleteForm
Builds the form to delete Block Visibility Group entities.

Namespace

Drupal\block_visibility_groups\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  if ($this
    ->getBlocksForGroup()) {

    // If there are blocks in this group then
    // create a dropdown to let the user choose what to do with blocks.
    $options[static::UNSET_BLOCKS] = $this
      ->t('Unset visibility group');
    $labels = $this
      ->getBlockVisibilityLabels($this->entityTypeManager
      ->getStorage('block_visibility_group'));
    unset($labels[$this->entity
      ->id()]);
    foreach ($labels as $type => $label) {
      $options[$type] = $this
        ->t('Move blocks to group: <em>@label</em>', [
        '@label' => $label,
      ]);
    }
    $options[static::DELETE_BLOCKS] = $this
      ->t('Delete all blocks');
    $form['blocks_op'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Current blocks'),
      '#options' => $options,
      '#description' => $this
        ->t('What do you want to do with the current blocks in this group?'),
    ];
  }
  else {

    // No blocks in this group.
    $form['no_blocks'] = [
      '#markup' => '<p>' . $this
        ->t('There no blocks assigned to this group.') . '</p>',
    ];
  }
  return $form;
}