class Component
Same name in this branch
- 10 core/modules/sdc/src/Plugin/Component.php \Drupal\sdc\Plugin\Component
Same name in other branches
- 11.x core/modules/sdc/src/Plugin/Component.php \Drupal\sdc\Plugin\Component
- 11.x core/lib/Drupal/Core/Plugin/Component.php \Drupal\Core\Plugin\Component
Simple value object that contains information about the component.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\Core\Plugin\Component extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of Component
7 files declare their use of Component
- ComponentNodeVisitor.php in core/
lib/ Drupal/ Core/ Template/ ComponentNodeVisitor.php - ComponentPluginManager.php in core/
lib/ Drupal/ Core/ Theme/ ComponentPluginManager.php - ComponentsTwigExtension.php in core/
lib/ Drupal/ Core/ Template/ ComponentsTwigExtension.php - ComponentValidator.php in core/
lib/ Drupal/ Core/ Theme/ Component/ ComponentValidator.php - ComponentValidatorTest.php in core/
tests/ Drupal/ Tests/ Core/ Theme/ Component/ ComponentValidatorTest.php
8 string references to 'Component'
- AnnotatedClassDiscoveryAutomatedProviders::prepareAnnotationDefinition in core/
modules/ migrate/ src/ Plugin/ Discovery/ AnnotatedClassDiscoveryAutomatedProviders.php - ComponentPluginManager::getDiscovery in core/
lib/ Drupal/ Core/ Theme/ ComponentPluginManager.php - ConfigMapperManager::findDefinitions in core/
modules/ config_translation/ src/ ConfigMapperManager.php - core.entity.schema.yml in core/
config/ schema/ core.entity.schema.yml - core/config/schema/core.entity.schema.yml
- DefaultPluginManager::findDefinitions in core/
lib/ Drupal/ Core/ Plugin/ DefaultPluginManager.php - Finds plugin definitions.
File
-
core/
lib/ Drupal/ Core/ Plugin/ Component.php, line 11
Namespace
Drupal\Core\PluginView source
class Component extends PluginBase {
/**
* The component's metadata.
*
* @var \Drupal\Core\Theme\Component\ComponentMetadata
*/
public readonly ComponentMetadata $metadata;
/**
* The component machine name.
*
* @var string
*/
public readonly string $machineName;
/**
* The Twig template for the component.
*
* @var string
*/
public readonly string $template;
/**
* The library definition to be attached with the component.
*
* @var array
*/
public readonly array $library;
/**
* Component constructor.
*
* @throws \Drupal\Core\Render\Component\Exception\InvalidComponentException
*/
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));
}
/**
* The template path.
*
* @return string|null
* The path to the template.
*/
public function getTemplatePath() : ?string {
return $this->metadata->path . DIRECTORY_SEPARATOR . $this->template;
}
/**
* The auto-computed library name.
*
* @return string
* The library name.
*/
public function getLibraryName() : string {
$library_id = $this->getPluginId();
$library_id = str_replace(':', '--', $library_id);
return sprintf('core/components.%s', $library_id);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
Component::$library | public | property | The library definition to be attached with the component. |
Component::$machineName | public | property | The component machine name. |
Component::$metadata | public | property | The component's metadata. |
Component::$template | public | property | The Twig template for the component. |
Component::getLibraryName | public | function | The auto-computed library name. |
Component::getTemplatePath | public | function | The template path. |
Component::__construct | public | function | Component constructor. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.