public function PluginType::__construct in Plugin 8.2
Constructs a new instance.
@internal
Parameters
mixed[] $definition: The plugin type definition.
\Symfony\Component\DependencyInjection\ContainerInterface $container: The service container.
\Drupal\Core\StringTranslation\TranslationInterface $string_translation: The string translator.
\Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver: The class resolver.
\Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager: The typed configuration manager.
mixed[] $definition:
File
- src/
PluginType/ PluginType.php, line 122
Class
- PluginType
- Provides a plugin type.
Namespace
Drupal\plugin\PluginTypeCode
public function __construct(array $definition, ContainerInterface $container, TranslationInterface $string_translation, ClassResolverInterface $class_resolver, TypedConfigManagerInterface $typed_config_manager) {
if (!is_string($definition['id']) || !strlen($definition['id'])) {
throw new \InvalidArgumentException(sprintf('The plugin type definition ID must be a non-empty string, but %s was given.', gettype($definition['id'])));
}
$this->id = $definition['id'];
$this->label = $definition['label'] = new TranslatableMarkup($definition['label'], [], [], $string_translation);
$this->description = $definition['description'] = isset($definition['description']) ? new TranslatableMarkup($definition['description'], [], [], $string_translation) : NULL;
if (array_key_exists('field_type', $definition)) {
if (!is_bool($definition['field_type'])) {
throw new \InvalidArgumentException(sprintf('The plugin type definition "field_type" item must be a boolean, but %s was given.', gettype($definition['field_type'])));
}
$this->fieldType = $definition['field_type'];
}
if (array_key_exists('plugin_definition_decorator_class', $definition)) {
$class = $definition['plugin_definition_decorator_class'];
if (!class_exists($class)) {
$type = is_scalar($class) ? $class : gettype($class);
throw new \InvalidArgumentException(sprintf('The plugin type definition "plugin_definition_decorator_class" item must valid class name, but "%s" was given and it does not exist.', $type));
}
$this->pluginDefinitionDecoratorClass = $definition['plugin_definition_decorator_class'];
}
if (isset($definition['plugin_configuration_schema_id'])) {
if (!is_string($definition['plugin_configuration_schema_id'])) {
throw new \InvalidArgumentException(sprintf('The plugin type definition "plugin_configuration_schema_id" item must be a string, but %s was given.', gettype($definition['field_type'])));
}
$this->configurationSchemaId = $definition['plugin_configuration_schema_id'];
}
$plugin_configuration_schema_id = $this
->getPluginConfigurationSchemaId('*');
if (!$typed_config_manager
->hasConfigSchema($plugin_configuration_schema_id)) {
throw new \InvalidArgumentException(sprintf('The plugin type definition "plugin_configuration_schema_id" item references the configuration schema "%s" ("%s"), which does not exist.', $plugin_configuration_schema_id, $this->configurationSchemaId));
}
$operations_provider_class = array_key_exists('operations_provider_class', $definition) ? $definition['operations_provider_class'] : DefaultPluginTypeOperationsProvider::class;
$this->operationsProvider = $class_resolver
->getInstanceFromDefinition($operations_provider_class);
$this->pluginManagerServiceId = $definition['plugin_manager_service_id'];
$this->provider = $definition['provider'];
$this->container = $container;
}