function DiscoveryTrait::doGetDefinition

Same name in other branches
  1. 9 core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php \Drupal\Component\Plugin\Discovery\DiscoveryTrait::doGetDefinition()
  2. 8.9.x core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php \Drupal\Component\Plugin\Discovery\DiscoveryTrait::doGetDefinition()
  3. 11.x core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php \Drupal\Component\Plugin\Discovery\DiscoveryTrait::doGetDefinition()

Gets a specific plugin definition.

Parameters

array $definitions: An array of the available plugin definitions.

string $plugin_id: A plugin id.

bool $exception_on_invalid: If TRUE, an invalid plugin ID will cause an exception to be thrown; if FALSE, NULL will be returned.

Return value

array|null A plugin definition, or NULL if the plugin ID is invalid and $exception_on_invalid is TRUE.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if $plugin_id is invalid and $exception_on_invalid is TRUE.

2 calls to DiscoveryTrait::doGetDefinition()
DiscoveryCachedTrait::getDefinition in core/lib/Drupal/Component/Plugin/Discovery/DiscoveryCachedTrait.php
DiscoveryTrait::getDefinition in core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php

File

core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php, line 43

Class

DiscoveryTrait

Namespace

Drupal\Component\Plugin\Discovery

Code

protected function doGetDefinition(array $definitions, $plugin_id, $exception_on_invalid) {
    // Avoid using a ternary that would create a copy of the array.
    if (isset($definitions[$plugin_id])) {
        return $definitions[$plugin_id];
    }
    elseif (!$exception_on_invalid) {
        return NULL;
    }
    $valid_ids = implode(', ', array_keys($definitions));
    throw new PluginNotFoundException($plugin_id, sprintf('The "%s" plugin does not exist. Valid plugin IDs for %s are: %s', $plugin_id, static::class, $valid_ids));
}

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