You are here

public function DashboardSectionStorage::deriveContextsFromRoute in Dashboards with Layout Builder 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/SectionStorage/DashboardSectionStorage.php \Drupal\dashboards\Plugin\SectionStorage\DashboardSectionStorage::deriveContextsFromRoute()

Derives the available plugin contexts from route values.

This should only be called during section storage instantiation, specifically for use by the routing system. For all non-routing usages, use \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextValue().

Parameters

mixed $value: The raw value.

mixed $definition: The parameter definition provided in the route options.

string $name: The name of the parameter.

array $defaults: The route defaults array.

Return value

\Drupal\Core\Plugin\Context\ContextInterface[] The available plugin contexts.

Overrides SectionStorageInterface::deriveContextsFromRoute

See also

\Drupal\Core\ParamConverter\ParamConverterInterface::convert()

1 method overrides DashboardSectionStorage::deriveContextsFromRoute()
UserDashboardSectionStorage::deriveContextsFromRoute in src/Plugin/SectionStorage/UserDashboardSectionStorage.php
Derives the available plugin contexts from route values.

File

src/Plugin/SectionStorage/DashboardSectionStorage.php, line 179

Class

DashboardSectionStorage
Dashboard section storage.

Namespace

Drupal\dashboards\Plugin\SectionStorage

Code

public function deriveContextsFromRoute($value, $definition, $name, array $defaults) {
  $contexts = [];
  $id = !empty($value) ? $value : (!empty($defaults['dashboard']) ? $defaults['dashboard'] : NULL);
  if ($id && ($entity = $this->entityTypeManager
    ->getStorage('dashboard')
    ->load($id))) {
    $contexts[Dashboard::CONTEXT_TYPE] = EntityContext::fromEntity($entity);
  }
  return $contexts;
}