function Component::__construct
Same name in this branch
- 11.x core/modules/sdc/src/Plugin/Component.php \Drupal\sdc\Plugin\Component::__construct()
Same name in other branches
- 10 core/modules/sdc/src/Plugin/Component.php \Drupal\sdc\Plugin\Component::__construct()
- 10 core/lib/Drupal/Core/Plugin/Component.php \Drupal\Core\Plugin\Component::__construct()
Component constructor.
Throws
\Drupal\Core\Render\Component\Exception\InvalidComponentException
File
-
core/
lib/ Drupal/ Core/ Plugin/ Component.php, line 46
Class
- Component
- Simple value object that contains information about the component.
Namespace
Drupal\Core\PluginCode
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if (str_contains($plugin_id, '/')) {
$message = sprintf('Component ID cannot contain slashes: %s', $plugin_id);
throw new InvalidComponentException($message);
}
$template = $plugin_definition['template'] ?? NULL;
if (!$template) {
$message = sprintf('Unable to find the Twig template for the component "%s".', $plugin_id);
throw new InvalidComponentException($message);
}
$this->template = $template;
$this->machineName = $plugin_definition['machineName'];
$this->library = $plugin_definition['library'] ?? [];
$this->metadata = new ComponentMetadata($plugin_definition, $configuration['app_root'], (bool) ($configuration['enforce_schemas'] ?? FALSE));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.