0

I have a theme that is a child theme of 'stable'.

Currently the base theme is defined in the info.yml file, however i don't want its parent theme to be so permanent.

I am looking for a way to be able to programatically change the base theme in code so that the theme could switch its parent on demand.

  • I have to ask why, as in what are you actually trying to achieve? – Jeff Burnz Aug 19 '16 at 16:09
  • 1
    Your also going to have to clear the cache when that changes. This is bad, your yml files should be committed to git because they do not change. Please give more context to your issue. Maybe you should be sub-theming your sub-theme of stable. It's easy enough to use different themes based on different contexts of a page on the fly. – Ryan Hartman Aug 19 '16 at 18:00
  • The answer to the question, as mentioned, is to modify theme definition yml files and cache flush. It's also very bad practice (self modifying code/configuration) that could easily blow up depending on what you're doing. You should take a different approach as Ryan mentions. – Shawn Conn Aug 19 '16 at 18:55
  • Ok, to clarify, i have a theme hosted on drupal.org, this theme can sit between a parent theme and a child theme. As the theme is in GIT on drupal.org it has to have a hardcoded parent theme which i have chosen as stable, however if someone wanted its parent theme to be lets say boostrap i would like them to have the ability to change it without having to 'fork' the theme by manually changing the base theme parameter in the yml file, so control of the base theme via the UI would be prefereble, i dont expect anyone to want to change it per page load. – Rob Holmes Aug 23 '16 at 6:43
0

So as it turns out an info.yml file can be altered inside HOOK_system_info_alter

To change the base theme definition of an existing theme you can use the following

function HOOK_system_info_alter(&$info, $file, $type) {
  if ($type == 'theme') {
    if ($info['name'] == 'YOUR THEME NAME') {
      $info['base theme'] = 'NEW_BASE_THEME_NAME';
    }
  }
}

As this hook is only fired when caches are flushed there is no need for a separate cache flush after the change is made.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.