class AddSectionController

Same name in other branches
  1. 8.9.x core/modules/layout_builder/src/Controller/AddSectionController.php \Drupal\layout_builder\Controller\AddSectionController
  2. 10 core/modules/layout_builder/src/Controller/AddSectionController.php \Drupal\layout_builder\Controller\AddSectionController
  3. 11.x core/modules/layout_builder/src/Controller/AddSectionController.php \Drupal\layout_builder\Controller\AddSectionController

Defines a controller to add a new section.

@internal Controller classes are internal.

Hierarchy

Expanded class hierarchy of AddSectionController

File

core/modules/layout_builder/src/Controller/AddSectionController.php, line 19

Namespace

Drupal\layout_builder\Controller
View source
class AddSectionController implements ContainerInjectionInterface {
    use AjaxHelperTrait;
    use LayoutRebuildTrait;
    
    /**
     * The layout tempstore repository.
     *
     * @var \Drupal\layout_builder\LayoutTempstoreRepositoryInterface
     */
    protected $layoutTempstoreRepository;
    
    /**
     * AddSectionController constructor.
     *
     * @param \Drupal\layout_builder\LayoutTempstoreRepositoryInterface $layout_tempstore_repository
     *   The layout tempstore repository.
     */
    public function __construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository) {
        $this->layoutTempstoreRepository = $layout_tempstore_repository;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container) {
        return new static($container->get('layout_builder.tempstore_repository'));
    }
    
    /**
     * Adds the new section.
     *
     * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
     *   The section storage.
     * @param int $delta
     *   The delta of the section to splice.
     * @param string $plugin_id
     *   The plugin ID of the layout to add.
     *
     * @return \Symfony\Component\HttpFoundation\Response
     *   The controller response.
     */
    public function build(SectionStorageInterface $section_storage, int $delta, $plugin_id) {
        $section_storage->insertSection($delta, new Section($plugin_id));
        $this->layoutTempstoreRepository
            ->set($section_storage);
        if ($this->isAjax()) {
            return $this->rebuildAndClose($section_storage);
        }
        else {
            $url = $section_storage->getLayoutBuilderUrl();
            return new RedirectResponse($url->setAbsolute()
                ->toString());
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AddSectionController::$layoutTempstoreRepository protected property The layout tempstore repository.
AddSectionController::build public function Adds the new section.
AddSectionController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
AddSectionController::__construct public function AddSectionController constructor.
AjaxHelperTrait::getRequestWrapperFormat protected function Gets the wrapper format of the current request.
AjaxHelperTrait::isAjax protected function Determines if the current request is via AJAX.
LayoutRebuildTrait::rebuildAndClose protected function Rebuilds the layout.
LayoutRebuildTrait::rebuildLayout protected function Rebuilds the layout.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.