TabDeleteForm.php in Block Tabs 8
File
src/Form/TabDeleteForm.php
View source
<?php
namespace Drupal\blocktabs\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\blocktabs\BlocktabsInterface;
class TabDeleteForm extends ConfirmFormBase {
protected $blockTabs;
protected $tab;
public function getQuestion() {
return $this
->t('Are you sure you want to delete the @tab tab from the %blocktabs blocktabs?', [
'%blocktabs' => $this->blockTabs
->label(),
'@tab' => $this->tab
->label(),
]);
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelUrl() {
return $this->blockTabs
->toUrl('edit-form');
}
public function getFormId() {
return 'tab_delete_form';
}
public function buildForm(array $form, FormStateInterface $form_state, BlocktabsInterface $blocktabs = NULL, $tab = NULL) {
$this->blockTabs = $blocktabs;
$this->tab = $this->blockTabs
->getTab($tab);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->blockTabs
->deleteTab($this->tab);
\Drupal::messenger()
->addMessage($this
->t('The tab %name has been deleted.', [
'%name' => $this->tab
->label(),
]));
$form_state
->setRedirectUrl($this->blockTabs
->toUrl('edit-form'));
}
}