"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/layout_builder/src/Form/LayoutRebuildConfirmFormBase.php" (26 Nov 2020, 3604 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "LayoutRebuildConfirmFormBase.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\layout_builder\Form;
    4 
    5 use Drupal\Core\Ajax\AjaxFormHelperTrait;
    6 use Drupal\Core\Form\ConfirmFormBase;
    7 use Drupal\Core\Form\FormStateInterface;
    8 use Drupal\layout_builder\Controller\LayoutRebuildTrait;
    9 use Drupal\layout_builder\LayoutBuilderHighlightTrait;
   10 use Drupal\layout_builder\LayoutTempstoreRepositoryInterface;
   11 use Drupal\layout_builder\SectionStorageInterface;
   12 use Symfony\Component\DependencyInjection\ContainerInterface;
   13 
   14 /**
   15  * Provides a base class for confirmation forms that rebuild the Layout Builder.
   16  *
   17  * @internal
   18  *   Form classes are internal.
   19  */
   20 abstract class LayoutRebuildConfirmFormBase extends ConfirmFormBase {
   21 
   22   use AjaxFormHelperTrait;
   23   use LayoutBuilderHighlightTrait;
   24   use LayoutRebuildTrait;
   25 
   26   /**
   27    * The layout tempstore repository.
   28    *
   29    * @var \Drupal\layout_builder\LayoutTempstoreRepositoryInterface
   30    */
   31   protected $layoutTempstoreRepository;
   32 
   33   /**
   34    * The section storage.
   35    *
   36    * @var \Drupal\layout_builder\SectionStorageInterface
   37    */
   38   protected $sectionStorage;
   39 
   40   /**
   41    * The field delta.
   42    *
   43    * @var int
   44    */
   45   protected $delta;
   46 
   47   /**
   48    * Constructs a new RemoveSectionForm.
   49    *
   50    * @param \Drupal\layout_builder\LayoutTempstoreRepositoryInterface $layout_tempstore_repository
   51    *   The layout tempstore repository.
   52    */
   53   public function __construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository) {
   54     $this->layoutTempstoreRepository = $layout_tempstore_repository;
   55   }
   56 
   57   /**
   58    * {@inheritdoc}
   59    */
   60   public static function create(ContainerInterface $container) {
   61     return new static(
   62       $container->get('layout_builder.tempstore_repository')
   63     );
   64   }
   65 
   66   /**
   67    * {@inheritdoc}
   68    */
   69   public function getCancelUrl() {
   70     return $this->sectionStorage->getLayoutBuilderUrl();
   71   }
   72 
   73   /**
   74    * {@inheritdoc}
   75    */
   76   public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL) {
   77     $this->sectionStorage = $section_storage;
   78     $this->delta = $delta;
   79 
   80     $form = parent::buildForm($form, $form_state);
   81 
   82     if ($this->isAjax()) {
   83       $form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit';
   84       $form['actions']['cancel']['#attributes']['class'][] = 'dialog-cancel';
   85       $target_highlight_id = !empty($this->uuid) ? $this->blockUpdateHighlightId($this->uuid) : $this->sectionUpdateHighlightId($delta);
   86       $form['#attributes']['data-layout-builder-target-highlight-id'] = $target_highlight_id;
   87     }
   88 
   89     // Mark this as an administrative page for JavaScript ("Back to site" link).
   90     $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
   91     return $form;
   92   }
   93 
   94   /**
   95    * {@inheritdoc}
   96    */
   97   public function submitForm(array &$form, FormStateInterface $form_state) {
   98     $this->handleSectionStorage($this->sectionStorage, $form_state);
   99 
  100     $this->layoutTempstoreRepository->set($this->sectionStorage);
  101 
  102     $form_state->setRedirectUrl($this->getCancelUrl());
  103   }
  104 
  105   /**
  106    * {@inheritdoc}
  107    */
  108   protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state) {
  109     return $this->rebuildAndClose($this->sectionStorage);
  110   }
  111 
  112   /**
  113    * Performs any actions on the section storage before saving.
  114    *
  115    * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
  116    *   The section storage.
  117    * @param \Drupal\Core\Form\FormStateInterface $form_state
  118    *   The current state of the form.
  119    */
  120   abstract protected function handleSectionStorage(SectionStorageInterface $section_storage, FormStateInterface $form_state);
  121 
  122 }