ImportConfirmForm.php in Fixed Block Content 8
File
src/Form/ImportConfirmForm.php
View source
<?php
namespace Drupal\fixed_block_content\Form;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityConfirmFormBase;
class ImportConfirmForm extends EntityConfirmFormBase {
public function getDescription() {
return $this
->t('The current default content will be be lost.') . ' ' . parent::getDescription();
}
public function getQuestion() {
return $this
->t('Are you sure you want to set the %block current content as the default?', [
'%block' => $this->entity
->label(),
]);
}
public function getCancelUrl() {
return Url::fromRoute('entity.fixed_block_content.collection');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity
->importDefaultContent();
$this->entity
->save();
$this
->messenger()
->addMessage($this
->t('Current contents of block %label saved as the default content.', [
'%label' => $this->entity
->label(),
]));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}