You are here

protected function DiscoveryTrait::doGetDefinition in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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: (optional) If TRUE, an invalid plugin ID will throw an exception. Defaults to FALSE.

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 48
Contains \Drupal\Component\Plugin\Discovery\DiscoveryTrait.

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;
  }
  throw new PluginNotFoundException($plugin_id, sprintf('The "%s" plugin does not exist.', $plugin_id));
}