You are here

CclDeleteConfirm.php in Custom Contextual Links 8

Namespace

Drupal\ccl\Form

File

src/Form/CclDeleteConfirm.php
View source
<?php

/**
 * @file
 * Contains \Drupal\ccl\Form\CclDeleteConfirm.
 */
namespace Drupal\ccl\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
class CclDeleteConfirm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'ccl_delete_confirm';
  }
  public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state, $id = NULL) {
    $form['clid'] = [
      '#type' => 'value',
      '#value' => $id,
    ];
    $title = db_query('SELECT title FROM {ccl} WHERE clid = :clid', [
      ':clid' => $id,
    ])
      ->fetchField();
    return confirm_form($form, t('Are you sure you want to delete the link %title?', [
      '%title' => $title,
    ]), 'admin/config/user-interface/ccl', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
  }
  public function submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
    if ($form_state
      ->getValue([
      'confirm',
    ])) {
      db_delete('ccl')
        ->condition('clid', $form_state
        ->getValue([
        'clid',
      ]))
        ->execute();
      drupal_set_message(t('Link removed.'));
      _ccl_update_cache();
      drupal_goto('admin/config/user-interface/ccl');
    }
  }

}

Classes

Namesort descending Description
CclDeleteConfirm