"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/layout_builder/src/Form/LayoutBuilderDisableForm.php" (26 Nov 2020, 3246 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 "LayoutBuilderDisableForm.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\layout_builder\Form;
    4 
    5 use Drupal\Core\Form\ConfirmFormBase;
    6 use Drupal\Core\Form\FormStateInterface;
    7 use Drupal\Core\Messenger\MessengerInterface;
    8 use Drupal\layout_builder\DefaultsSectionStorageInterface;
    9 use Drupal\layout_builder\LayoutTempstoreRepositoryInterface;
   10 use Drupal\layout_builder\SectionStorageInterface;
   11 use Symfony\Component\DependencyInjection\ContainerInterface;
   12 
   13 /**
   14  * Disables Layout Builder for a given default.
   15  *
   16  * @internal
   17  *   Form classes are internal.
   18  */
   19 class LayoutBuilderDisableForm extends ConfirmFormBase {
   20 
   21   /**
   22    * The layout tempstore repository.
   23    *
   24    * @var \Drupal\layout_builder\LayoutTempstoreRepositoryInterface
   25    */
   26   protected $layoutTempstoreRepository;
   27 
   28   /**
   29    * The section storage.
   30    *
   31    * @var \Drupal\layout_builder\DefaultsSectionStorageInterface
   32    */
   33   protected $sectionStorage;
   34 
   35   /**
   36    * Constructs a new RevertOverridesForm.
   37    *
   38    * @param \Drupal\layout_builder\LayoutTempstoreRepositoryInterface $layout_tempstore_repository
   39    *   The layout tempstore repository.
   40    * @param \Drupal\Core\Messenger\MessengerInterface $messenger
   41    *   The messenger service.
   42    */
   43   public function __construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository, MessengerInterface $messenger) {
   44     $this->layoutTempstoreRepository = $layout_tempstore_repository;
   45     $this->setMessenger($messenger);
   46   }
   47 
   48   /**
   49    * {@inheritdoc}
   50    */
   51   public static function create(ContainerInterface $container) {
   52     return new static(
   53       $container->get('layout_builder.tempstore_repository'),
   54       $container->get('messenger')
   55     );
   56   }
   57 
   58   /**
   59    * {@inheritdoc}
   60    */
   61   public function getFormId() {
   62     return 'layout_builder_disable_form';
   63   }
   64 
   65   /**
   66    * {@inheritdoc}
   67    */
   68   public function getQuestion() {
   69     return $this->t('Are you sure you want to disable Layout Builder?');
   70   }
   71 
   72   /**
   73    * {@inheritdoc}
   74    */
   75   public function getDescription() {
   76     return $this->t('All customizations will be removed. This action cannot be undone.');
   77   }
   78 
   79   /**
   80    * {@inheritdoc}
   81    */
   82   public function getCancelUrl() {
   83     return $this->sectionStorage->getRedirectUrl();
   84   }
   85 
   86   /**
   87    * {@inheritdoc}
   88    */
   89   public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL) {
   90     if (!$section_storage instanceof DefaultsSectionStorageInterface) {
   91       throw new \InvalidArgumentException(sprintf('The section storage with type "%s" and ID "%s" does not provide defaults', $section_storage->getStorageType(), $section_storage->getStorageId()));
   92     }
   93 
   94     $this->sectionStorage = $section_storage;
   95     // Mark this as an administrative page for JavaScript ("Back to site" link).
   96     $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
   97     return parent::buildForm($form, $form_state);
   98   }
   99 
  100   /**
  101    * {@inheritdoc}
  102    */
  103   public function submitForm(array &$form, FormStateInterface $form_state) {
  104     $this->sectionStorage->disableLayoutBuilder()->save();
  105     $this->layoutTempstoreRepository->delete($this->sectionStorage);
  106 
  107     $this->messenger()->addMessage($this->t('Layout Builder has been disabled.'));
  108     $form_state->setRedirectUrl($this->getCancelUrl());
  109   }
  110 
  111 }