class AddSectionController in Drupal 8
Same name and namespace in other branches
- 9 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
- class \Drupal\layout_builder\Controller\AddSectionController implements ContainerInjectionInterface uses AjaxHelperTrait, LayoutRebuildTrait
Expanded class hierarchy of AddSectionController
File
- core/
modules/ layout_builder/ src/ Controller/ AddSectionController.php, line 19
Namespace
Drupal\layout_builder\ControllerView 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, $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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AddSectionController:: |
protected | property | The layout tempstore repository. | |
AddSectionController:: |
public | function | Adds the new section. | |
AddSectionController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
AddSectionController:: |
public | function | AddSectionController constructor. | |
AjaxHelperTrait:: |
protected | function | Gets the wrapper format of the current request. | |
AjaxHelperTrait:: |
protected | function | Determines if the current request is via AJAX. | |
LayoutRebuildTrait:: |
protected | function | Rebuilds the layout. | |
LayoutRebuildTrait:: |
protected | function | Rebuilds the layout. |