Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ComponentPluginManager.php

function ComponentPluginManager::alterDefinition

Alters the plugin definition with computed properties.

Parameters

array $definition: The definition.

Return value

array The altered definition.

File

core/lib/Drupal/Core/Theme/ComponentPluginManager.php, line 300

Class

ComponentPluginManager
Defines a plugin manager to deal with components.

Namespace

Drupal\Core\Theme

Code

protected function alterDefinition(array $definition) : array {
    $definition['extension_type'] = $this->moduleHandler
        ->moduleExists($definition['provider']) ? ExtensionType::Module : ExtensionType::Theme;
    $metadata_path = $definition[YamlDirectoryDiscovery::FILE_KEY];
    $component_directory = $this->fileSystem
        ->dirname($metadata_path);
    $definition['path'] = $component_directory;
    [
        ,
        $machine_name,
    ] = explode(':', $definition['id']);
    $definition['machineName'] = $machine_name;
    $definition['library'] = $this->libraryFromDefinition($definition);
    // Discover the template.
    $template = $this->findAsset($component_directory, $definition['machineName'], 'twig');
    $definition['template'] = basename($template);
    $definition['documentation'] = 'No documentation found. Add a README.md in your component directory.';
    $documentation_path = sprintf('%s/README.md', $this->fileSystem
        ->dirname($metadata_path));
    if (file_exists($documentation_path)) {
        $definition['documentation'] = file_get_contents($documentation_path);
    }
    return $definition;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal