dependent_country_state-1.0.6/src/Form/DeletePincodeForm.php

src/Form/DeletePincodeForm.php
<?php

namespace Drupal\dependent_country_state\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Url;

/**
 * DeleteStateForm class will delete state one by one based on state id.
 *
 * @package Drupal\dependent_country_state\Form
 */
class DeletePincodeForm extends ConfirmFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'delete_pincode_form';
  }

  /**
   * Store state id from the URL.
   *
   * @var sid
   */
  public $sid;

  /**
   * This function will ask confirmation.
   */
  public function getQuestion() {
    return $this->t('Do you want to delete %sid?', ['%sid' => $this->sid]);
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {

    return new Url('country_state.city');

  }

  /**
   * {@inheritdoc}
   */
  public function getDescription() {

    return $this->t('Only do this if you are sure!');

  }

  /**
   * {@inheritdoc}
   */
  public function getConfirmText() {

    return $this->t('Delete it!');
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelText() {

    return $this->t('Cancel');
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $sid = NULL) {

    $this->id = $sid;

    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

    $query = \Drupal::database();

    $query->delete('dependent_pincode')
      ->condition('id', $this->id)
      ->execute();

    \Drupal::messenger()->addMessage($this->t('Deleted Successfully'), 'status', TRUE);
    $form_state->setRedirect('country_state.pincode');
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc