function LayoutSectionStorageParamConverter::convert

Same name in other branches
  1. 10 core/modules/layout_builder/src/Routing/LayoutSectionStorageParamConverter.php \Drupal\layout_builder\Routing\LayoutSectionStorageParamConverter::convert()
  2. 11.x core/modules/layout_builder/src/Routing/LayoutSectionStorageParamConverter.php \Drupal\layout_builder\Routing\LayoutSectionStorageParamConverter::convert()

Overrides ParamConverterInterface::convert

File

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

Class

LayoutSectionStorageParamConverter
Loads the section storage from the routing defaults.

Namespace

Drupal\layout_builder\Routing

Code

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);
}

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