You are here

class MultiblockDeleteForm in MultiBlock 8

Same name in this branch
  1. 8 src/MultiblockDeleteForm.php \Drupal\multiblock\MultiblockDeleteForm
  2. 8 src/Form/MultiblockDeleteForm.php \Drupal\multiblock\Form\MultiblockDeleteForm

Hierarchy

Expanded class hierarchy of MultiblockDeleteForm

File

src/MultiblockDeleteForm.php, line 4

Namespace

Drupal\multiblock
View source
class MultiblockDeleteForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'multiblock_delete_form';
  }
  public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state, $delta = NULL) {
    $block = multiblock_get_block($delta);
    if (empty($block)) {
      drupal_set_message(t('The multiblock with the delta @delta was not found.', [
        '@delta' => $delta,
      ]), 'error');
      return [];
    }
    $form['delta'] = [
      '#type' => 'value',
      '#value' => $delta,
    ];
    return confirm_form($form, t('Delete the block instance %title?', [
      '%title' => $block->title,
    ]), 'admin/structure/block/instances', t('This will delete the instance of the block %title.', [
      '%title' => $block->title,
    ]), t('Delete'), t('Cancel'));
  }
  public function submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
    if (multiblock_delete($form_state
      ->getValue([
      'delta',
    ]))) {
      drupal_set_message(t('Block successfully deleted!'));
    }
    else {
      drupal_set_message(t('There was a problem deleting the block'));
    }
    $form_state
      ->set([
      'redirect',
    ], 'admin/structure/block/instances');
  }

}

Members