class Component

Same name in this branch
  1. 11.x core/lib/Drupal/Core/Plugin/Component.php \Drupal\Core\Plugin\Component
Same name and namespace in other branches
  1. 10 core/modules/sdc/src/Plugin/Component.php \Drupal\sdc\Plugin\Component
  2. 10 core/lib/Drupal/Core/Plugin/Component.php \Drupal\Core\Plugin\Component

Simple value object that contains information about the component.

@internal

Hierarchy

Expanded class hierarchy of Component

6 files declare their use of Component
ComponentNodeVisitor.php in core/modules/sdc/src/Twig/ComponentNodeVisitor.php
ComponentPluginManager.php in core/modules/sdc/src/ComponentPluginManager.php
ComponentValidator.php in core/modules/sdc/src/Component/ComponentValidator.php
ComponentValidatorTest.php in core/modules/sdc/tests/src/Unit/ComponentValidatorTest.php
sdc.module in core/modules/sdc/sdc.module
Module implementation file.

... See full list

10 string references to 'Component'
AnnotatedDiscoveryAutomatedProvidersTrait::prepareAnnotationDefinition in core/modules/migrate/src/Plugin/Discovery/AnnotatedDiscoveryAutomatedProvidersTrait.php
Prepares the annotation definition.
AttributeClassDiscoveryAutomatedProviders::prepareAttributeDefinition in core/modules/migrate/src/Plugin/Discovery/AttributeClassDiscoveryAutomatedProviders.php
Prepares the attribute definition.
ComponentPluginManager::getDiscovery in core/lib/Drupal/Core/Theme/ComponentPluginManager.php
Gets the plugin discovery.
ConfigMapperManager::findDefinitions in core/modules/config_translation/src/ConfigMapperManager.php
Finds plugin definitions.
core.entity.schema.yml in core/config/schema/core.entity.schema.yml
core/config/schema/core.entity.schema.yml

... See full list

File

core/modules/sdc/src/Plugin/Component.php, line 14

Namespace

Drupal\sdc\Plugin
View source
final class Component extends PluginBase {
    
    /**
     * The component's metadata.
     *
     * @var \Drupal\sdc\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\sdc\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('sdc/%s', $library_id);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
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. Overrides PluginBase::__construct
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 3
DependencySerializationTrait::__wakeup public function 3
MessengerTrait::$messenger protected property The messenger. 25
MessengerTrait::messenger public function Gets the messenger. 25
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin ID.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin ID of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable Deprecated public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.