You are here

class LayoutTempstoreRouteEnhancer in Drupal 10

Loads the section storage from the layout tempstore.

Hierarchy

Expanded class hierarchy of LayoutTempstoreRouteEnhancer

1 file declares its use of LayoutTempstoreRouteEnhancer
LayoutTempstoreRouteEnhancerTest.php in core/modules/layout_builder/tests/src/Unit/LayoutTempstoreRouteEnhancerTest.php
1 string reference to 'LayoutTempstoreRouteEnhancer'
layout_builder.services.yml in core/modules/layout_builder/layout_builder.services.yml
core/modules/layout_builder/layout_builder.services.yml
1 service uses LayoutTempstoreRouteEnhancer
layout_builder.tempstore.route_enhancer in core/modules/layout_builder/layout_builder.services.yml
Drupal\layout_builder\Routing\LayoutTempstoreRouteEnhancer

File

core/modules/layout_builder/src/Routing/LayoutTempstoreRouteEnhancer.php, line 14

Namespace

Drupal\layout_builder\Routing
View source
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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LayoutTempstoreRouteEnhancer::$layoutTempstoreRepository protected property The layout tempstore repository.
LayoutTempstoreRouteEnhancer::enhance public function Updates the defaults for a route definition based on the request. Overrides EnhancerInterface::enhance
LayoutTempstoreRouteEnhancer::__construct public function Constructs a new LayoutTempstoreRouteEnhancer.