class DiscardLayoutChangesForm
Same name and namespace in other branches
- 11.x core/modules/layout_builder/src/Form/DiscardLayoutChangesForm.php \Drupal\layout_builder\Form\DiscardLayoutChangesForm
- 10 core/modules/layout_builder/src/Form/DiscardLayoutChangesForm.php \Drupal\layout_builder\Form\DiscardLayoutChangesForm
- 8.9.x core/modules/layout_builder/src/Form/DiscardLayoutChangesForm.php \Drupal\layout_builder\Form\DiscardLayoutChangesForm
Discards any pending changes to the layout.
@internal Form classes are internal.
Hierarchy
- class \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements \Drupal\Core\Form\ConfirmFormInterface extends \Drupal\Core\Form\FormBase
- class \Drupal\layout_builder\Form\DiscardLayoutChangesForm extends \Drupal\Core\Form\ConfirmFormBase
- class \Drupal\Core\Form\ConfirmFormBase implements \Drupal\Core\Form\ConfirmFormInterface extends \Drupal\Core\Form\FormBase
Expanded class hierarchy of DiscardLayoutChangesForm
File
-
core/
modules/ layout_builder/ src/ Form/ DiscardLayoutChangesForm.php, line 18
Namespace
Drupal\layout_builder\FormView source
class DiscardLayoutChangesForm extends ConfirmFormBase {
/**
* The layout tempstore repository.
*
* @var \Drupal\layout_builder\LayoutTempstoreRepositoryInterface
*/
protected $layoutTempstoreRepository;
/**
* The messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* The section storage.
*
* @var \Drupal\layout_builder\SectionStorageInterface
*/
protected $sectionStorage;
/**
* Constructs a new DiscardLayoutChangesForm.
*
* @param \Drupal\layout_builder\LayoutTempstoreRepositoryInterface $layout_tempstore_repository
* The layout tempstore repository.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
*/
public function __construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository, MessengerInterface $messenger) {
$this->layoutTempstoreRepository = $layout_tempstore_repository;
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('layout_builder.tempstore_repository'), $container->get('messenger'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'layout_builder_discard_changes';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to discard your layout changes?');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return $this->sectionStorage
->getRedirectUrl();
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL) {
$this->sectionStorage = $section_storage;
// Mark this as an administrative page for JavaScript ("Back to site" link).
$form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->layoutTempstoreRepository
->delete($this->sectionStorage);
$this->messenger
->addMessage($this->t('The changes to the layout have been discarded.'));
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.