LayoutRebuildConfirmFormBase.php in Drupal 8
File
core/modules/layout_builder/src/Form/LayoutRebuildConfirmFormBase.php
View source
<?php
namespace Drupal\layout_builder\Form;
use Drupal\Core\Ajax\AjaxFormHelperTrait;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\layout_builder\Controller\LayoutRebuildTrait;
use Drupal\layout_builder\LayoutBuilderHighlightTrait;
use Drupal\layout_builder\LayoutTempstoreRepositoryInterface;
use Drupal\layout_builder\SectionStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class LayoutRebuildConfirmFormBase extends ConfirmFormBase {
use AjaxFormHelperTrait;
use LayoutBuilderHighlightTrait;
use LayoutRebuildTrait;
protected $layoutTempstoreRepository;
protected $sectionStorage;
protected $delta;
public function __construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository) {
$this->layoutTempstoreRepository = $layout_tempstore_repository;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('layout_builder.tempstore_repository'));
}
public function getCancelUrl() {
return $this->sectionStorage
->getLayoutBuilderUrl();
}
public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL) {
$this->sectionStorage = $section_storage;
$this->delta = $delta;
$form = parent::buildForm($form, $form_state);
if ($this
->isAjax()) {
$form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit';
$form['actions']['cancel']['#attributes']['class'][] = 'dialog-cancel';
$target_highlight_id = !empty($this->uuid) ? $this
->blockUpdateHighlightId($this->uuid) : $this
->sectionUpdateHighlightId($delta);
$form['#attributes']['data-layout-builder-target-highlight-id'] = $target_highlight_id;
}
$form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->handleSectionStorage($this->sectionStorage, $form_state);
$this->layoutTempstoreRepository
->set($this->sectionStorage);
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state) {
return $this
->rebuildAndClose($this->sectionStorage);
}
protected abstract function handleSectionStorage(SectionStorageInterface $section_storage, FormStateInterface $form_state);
}