class LayoutSectionStorageParamConverter

Same name in other branches
  1. 9 core/modules/layout_builder/src/Routing/LayoutSectionStorageParamConverter.php \Drupal\layout_builder\Routing\LayoutSectionStorageParamConverter
  2. 10 core/modules/layout_builder/src/Routing/LayoutSectionStorageParamConverter.php \Drupal\layout_builder\Routing\LayoutSectionStorageParamConverter

Loads the section storage from the routing defaults.

@internal Tagged services are internal.

Hierarchy

Expanded class hierarchy of LayoutSectionStorageParamConverter

1 file declares its use of LayoutSectionStorageParamConverter
LayoutSectionStorageParamConverterTest.php in core/modules/layout_builder/tests/src/Unit/LayoutSectionStorageParamConverterTest.php
1 string reference to 'LayoutSectionStorageParamConverter'
layout_builder.services.yml in core/modules/layout_builder/layout_builder.services.yml
core/modules/layout_builder/layout_builder.services.yml
1 service uses LayoutSectionStorageParamConverter
layout_builder.param_converter in core/modules/layout_builder/layout_builder.services.yml
Drupal\layout_builder\Routing\LayoutSectionStorageParamConverter

File

core/modules/layout_builder/src/Routing/LayoutSectionStorageParamConverter.php, line 15

Namespace

Drupal\layout_builder\Routing
View source
class LayoutSectionStorageParamConverter implements ParamConverterInterface {
    
    /**
     * The section storage manager.
     *
     * @var \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface
     */
    protected $sectionStorageManager;
    
    /**
     * Constructs a new LayoutSectionStorageParamConverter.
     *
     * @param \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface $section_storage_manager
     *   The section storage manager.
     */
    public function __construct(SectionStorageManagerInterface $section_storage_manager) {
        $this->sectionStorageManager = $section_storage_manager;
    }
    
    /**
     * {@inheritdoc}
     */
    public function convert($value, $definition, $name, array $defaults) {
        // If no section storage type is specified or if it is invalid, return.
        if (!isset($defaults['section_storage_type']) || !$this->sectionStorageManager
            ->hasDefinition($defaults['section_storage_type'])) {
            return NULL;
        }
        $type = $defaults['section_storage_type'];
        // Load an empty instance and derive the available contexts.
        $contexts = $this->sectionStorageManager
            ->loadEmpty($type)
            ->deriveContextsFromRoute($value, $definition, $name, $defaults);
        // Attempt to load a full instance based on the context.
        return $this->sectionStorageManager
            ->load($type, $contexts);
    }
    
    /**
     * {@inheritdoc}
     */
    public function applies($definition, $name, Route $route) {
        return !empty($definition['layout_builder_section_storage']) || !empty($definition['layout_builder_tempstore']);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
LayoutSectionStorageParamConverter::$sectionStorageManager protected property The section storage manager.
LayoutSectionStorageParamConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
LayoutSectionStorageParamConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
LayoutSectionStorageParamConverter::__construct public function Constructs a new LayoutSectionStorageParamConverter.

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