You are here

function hook_components_namespaces_alter in Components! 3.x

Alter the list of namespaces for a particular theme.

Parameters

array $namespaces: The array of Twig namespaces where the key is the machine name of the namespace and the value is an array of directory paths that are relative to the Drupal root.

string $theme: The name of the theme that the namespaces are defined for.

See also

https://www.drupal.org/node/3190969

1 function implements hook_components_namespaces_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

components_test_components_namespaces_alter in tests/modules/components_test/components_test.module
Implements hook_components_namespaces_alter().

File

./components.api.php, line 25
Hooks related to the Components module.

Code

function hook_components_namespaces_alter(array &$namespaces, string $theme) {

  // Add a new namespace.
  $namespaces['new_namespace'] = [
    // Paths must be relative to the Drupal root.
    'libraries/new-components',
    'themes/contrib/zen/new-components',
    // Even paths adjacent to the Drupal root will work.
    '../vendor/newFangled/new-components',
  ];

  // If you only want to change namespaces for a specific theme the $theme
  // parameter has the name of the currently active theme.
  if ($theme === 'zen') {

    // Append a path to an existing namespace.
    $namespaces['components'][] = drupal_get_path('theme', 'zen') . '/components';
  }
}