function Component::__construct

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

Component constructor.

Throws

\Drupal\sdc\Exception\InvalidComponentException

File

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

Class

Component
Simple value object that contains information about the component.

Namespace

Drupal\sdc\Plugin

Code

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.