LayoutTempstoreRouteEnhancer.php

Same filename in other branches
  1. 9 core/modules/layout_builder/src/Routing/LayoutTempstoreRouteEnhancer.php
  2. 10 core/modules/layout_builder/src/Routing/LayoutTempstoreRouteEnhancer.php

Namespace

Drupal\layout_builder\Routing

File

core/modules/layout_builder/src/Routing/LayoutTempstoreRouteEnhancer.php

View source
<?php

namespace Drupal\layout_builder\Routing;

use Drupal\Core\Routing\EnhancerInterface;
use Drupal\Core\Routing\RouteObjectInterface;
use Drupal\layout_builder\LayoutTempstoreRepositoryInterface;
use Drupal\layout_builder\SectionStorageInterface;
use Symfony\Component\HttpFoundation\Request;

/**
 * Loads the section storage from the layout tempstore.
 */
class LayoutTempstoreRouteEnhancer implements EnhancerInterface {
    
    /**
     * The layout tempstore repository.
     *
     * @var \Drupal\layout_builder\LayoutTempstoreRepositoryInterface
     */
    protected $layoutTempstoreRepository;
    
    /**
     * Constructs a new LayoutTempstoreRouteEnhancer.
     *
     * @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 function enhance(array $defaults, Request $request) {
        $parameters = $defaults[RouteObjectInterface::ROUTE_OBJECT]->getOption('parameters');
        if (isset($parameters['section_storage']['layout_builder_tempstore']) && isset($defaults['section_storage']) && $defaults['section_storage'] instanceof SectionStorageInterface) {
            $defaults['section_storage'] = $this->layoutTempstoreRepository
                ->get($defaults['section_storage']);
        }
        return $defaults;
    }

}

Classes

Title Deprecated Summary
LayoutTempstoreRouteEnhancer Loads the section storage from the layout tempstore.

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