function ComponentNegotiator::negotiate

Same name in this branch
  1. 11.x core/modules/sdc/src/ComponentNegotiator.php \Drupal\sdc\ComponentNegotiator::negotiate()
Same name in other branches
  1. 10 core/modules/sdc/src/ComponentNegotiator.php \Drupal\sdc\ComponentNegotiator::negotiate()
  2. 10 core/lib/Drupal/Core/Theme/ComponentNegotiator.php \Drupal\Core\Theme\ComponentNegotiator::negotiate()

Negotiates the active component for the current request.

Parameters

string $component_id: The requested component id. Ex: 'my-button', 'my-button--primary', 'component_example:my-button--primary', ...

array[] $all_definitions: All the plugin definitions for components keyed by plugin ID.

Return value

string|null The negotiated plugin ID or null if no negotiation was successful.

File

core/lib/Drupal/Core/Theme/ComponentNegotiator.php, line 46

Class

ComponentNegotiator
Determines which component should be used.

Namespace

Drupal\Core\Theme

Code

public function negotiate(string $component_id, array $all_definitions) : ?string {
    $cache_key = $this->generateCacheKey($component_id);
    $cached_data = $this->cache[$cache_key] ?? NULL;
    if (isset($cached_data)) {
        return $cached_data;
    }
    $negotiated = $this->doNegotiate($component_id, $all_definitions);
    $this->cache[$cache_key] = $negotiated;
    return $negotiated;
}

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