function ComponentNegotiator::doNegotiate

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

Negotiates the active component for the current request.

Parameters

string $component_id: The requested component id. Ex: 'my-button', 'my-button--primary', 'sdc_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.

1 call to ComponentNegotiator::doNegotiate()
ComponentNegotiator::negotiate in core/modules/sdc/src/ComponentNegotiator.php
Negotiates the active component for the current request.

File

core/modules/sdc/src/ComponentNegotiator.php, line 81

Class

ComponentNegotiator
Determines which component should be used.

Namespace

Drupal\sdc

Code

private function doNegotiate(string $component_id, array $all_definitions) : ?string {
    // Consider only the component definitions matching the component ID in the
    // 'replaces' key.
    $matches = array_filter($all_definitions, static fn(array $definition) => $component_id === ($definition['replaces'] ?? NULL));
    $negotiated_plugin_id = $this->maybeNegotiateByTheme($matches);
    if ($negotiated_plugin_id) {
        return $negotiated_plugin_id;
    }
    return $this->maybeNegotiateByModule($matches);
}

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