You are here

public function PluginType::ensureTypedPluginDefinition in Plugin 8.2

Ensures that a plugin definition is typed.

Parameters

\Drupal\plugin\PluginDefinition\PluginDefinitionInterface|mixed $plugin_definition: An original plugin definition of this type. It may already be typed.

Return value

\Drupal\plugin\PluginDefinition\PluginDefinitionInterface The typed plugin definition.

Throws

\InvalidArgumentException Thrown when a typed definition could not be returned.

Overrides PluginTypeInterface::ensureTypedPluginDefinition

File

src/PluginType/PluginType.php, line 212

Class

PluginType
Provides a plugin type.

Namespace

Drupal\plugin\PluginType

Code

public function ensureTypedPluginDefinition($plugin_definition) {
  if ($this->pluginDefinitionDecoratorClass && !$plugin_definition instanceof $this->pluginDefinitionDecoratorClass) {
    $plugin_definition_decorator_class = $this->pluginDefinitionDecoratorClass;
    return $plugin_definition_decorator_class::createFromDecoratedDefinition($plugin_definition);
  }
  elseif ($plugin_definition instanceof PluginDefinitionInterface) {
    return $plugin_definition;
  }
  else {
    throw new \Exception(sprintf('A plugin definition of plugin type %s does not implement required %s, but its type also does not specify a plugin definition decorator.', $this
      ->getId(), PluginDefinitionInterface::class));
  }
}