function ComponentPluginManager::alterDefinition

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

Alters the plugin definition with computed properties.

Parameters

array $definition: The definition.

Return value

array The altered definition.

File

core/modules/sdc/src/ComponentPluginManager.php, line 307

Class

ComponentPluginManager
Defines a plugin manager to deal with sdc.

Namespace

Drupal\sdc

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;
}

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