Score:-2

How can I override the emulsify libraries in a .theme file?

tk flag

I want to override the emulsify libraries in a .theme file.

I have used all the default theme hooks in the theme file, but they do not work. The following code work in a custom module.

function custom_module_system_info_alter(array &$info, Extension $file, $type) {
  $namespaces = [
    'base' => '00-base',
    'atoms' => '01-atoms',
    'molecules' => '02-molecules',
    'organisms' => '03-organisms',
    'templates' => '04-templates',
  ];

  // The ComponentsLoader will prepend our paths with the path,
  // so let's undo that by putting as many '../' before our path as
  // necessary.
  $theme_path = implode('/', array_merge(array_fill(0, count(explode('/', $file->getPath())), '..'), [drupal_get_path('theme', 'custom_theme')]));

  foreach ($namespaces as $namespace => $dirname) {
    $original_paths = $info['component-libraries'][$namespace]['paths'];
    $override_paths = [$theme_path . '/component-overrides/' . $dirname];

    if (is_array($original_paths)) {
      $info['component-libraries'][$namespace]['paths'] = array_merge($override_paths, $original_paths);
    }
  }
}
id flag
Please include your custom code in the Question.
Kevin avatar
in flag
Not all hooks are doable at the theme level. You need to include relevant code.
Jaypan avatar
de flag
I don't believe info_alter() hooks are called from a theme. Themes are for markup of data, and info hooks are for generating data, which isn't part of the theme layer. You probably need a custom module to implement this hook.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.