trait DiscoveryTrait in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php \Drupal\Component\Plugin\Discovery\DiscoveryTrait
Hierarchy
- trait \Drupal\Component\Plugin\Discovery\DiscoveryTrait
See also
Drupal\Component\Plugin\Discovery\DiscoveryInterface
6 files declare their use of DiscoveryTrait
- AnnotatedClassDiscovery.php in core/
lib/ Drupal/ Component/ Annotation/ Plugin/ Discovery/ AnnotatedClassDiscovery.php - Contains \Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery.
- ConfigSchemaDiscovery.php in core/
lib/ Drupal/ Core/ Config/ Schema/ ConfigSchemaDiscovery.php - Contains \Drupal\Core\Config\Schema\ConfigSchemaDiscovery.
- HookDiscovery.php in core/
lib/ Drupal/ Core/ Plugin/ Discovery/ HookDiscovery.php - Contains \Drupal\Core\Plugin\Discovery\HookDiscovery.
- InfoHookDecorator.php in core/
lib/ Drupal/ Core/ Plugin/ Discovery/ InfoHookDecorator.php - Contains \Drupal\Core\Plugin\Discovery\InfoHookDecorator.
- PluginManagerBase.php in core/
lib/ Drupal/ Component/ Plugin/ PluginManagerBase.php - Contains \Drupal\Component\Plugin\PluginManagerBase.
File
- core/
lib/ Drupal/ Component/ Plugin/ Discovery/ DiscoveryTrait.php, line 15 - Contains \Drupal\Component\Plugin\Discovery\DiscoveryTrait.
Namespace
Drupal\Component\Plugin\DiscoveryView source
trait DiscoveryTrait {
/**
* {@inheritdoc}
*/
public abstract function getDefinitions();
/**
* {@inheritdoc}
*/
public function getDefinition($plugin_id, $exception_on_invalid = TRUE) {
$definitions = $this
->getDefinitions();
return $this
->doGetDefinition($definitions, $plugin_id, $exception_on_invalid);
}
/**
* Gets a specific plugin definition.
*
* @param array $definitions
* An array of the available plugin definitions.
* @param string $plugin_id
* A plugin id.
* @param bool $exception_on_invalid
* (optional) If TRUE, an invalid plugin ID will throw an exception.
* Defaults to FALSE.
*
* @return 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.
*/
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));
}
/**
* {@inheritdoc}
*/
public function hasDefinition($plugin_id) {
return (bool) $this
->getDefinition($plugin_id, FALSE);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DiscoveryTrait:: |
protected | function | Gets a specific plugin definition. | |
DiscoveryTrait:: |
public | function | 3 | |
DiscoveryTrait:: |
abstract public | function | 9 | |
DiscoveryTrait:: |
public | function |