function LayoutTempstoreParamConverter::convert

Overrides ParamConverterInterface::convert

File

core/modules/layout_builder/src/Routing/LayoutTempstoreParamConverter.php, line 48

Class

LayoutTempstoreParamConverter
Loads the section storage from the layout tempstore.

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.
    if ($section_storage = $this->sectionStorageManager
        ->load($type, $contexts)) {
        // Pass the plugin through the tempstore repository.
        return $this->layoutTempstoreRepository
            ->get($section_storage);
    }
}

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