CSS file added as module CSS, should be theme CSS for custom layouts in theme

Comments

henrijs.seso’s picture

Case - layout plugin css file in theme needs to override base theme css file. Base theme css file has group 100 (theme css group), layout css file has group 0 (module css group).

Maybe check to add_meta() should be added along the (ugly) lines of

        $theme = drupal_get_path('theme', $this->plugins['layout']['module']) . '/' . $this->plugins['layout']['module'] . '.info';
        if (isset($theme)) {
          // Add from here with 'group' CSS_THEME or do more checks with $info = drupal_parse_info_file($theme);
        }

Workaround for now seems to be this even uglier code

function THEMENAME_css_alter(&$css) {
  // Workaround for @SEE drupal.org/node/1618168
  $theme_path = drupal_get_path('theme', variable_get('theme_default', NULL));
  foreach ($css as $path => $settings) {
    // Second check is relevant to my case, REMOVE IT and add your own additional checks.
    if (stripos($path, $theme_path) !== FALSE && substr($path, -5, 5) == '.less') {
      $css[$path]['group'] = CSS_THEME;
    }
  }
}
merlinofchaos’s picture

Why would a module ever add a CSS file in the theme group? I'm not following.

henrijs.seso’s picture

Priority: Normal » Minor
Status: Active » Closed (works as designed)

Module - never, but custom layout css in theme may want to override some other theme css. For example, there is css file in theme that says link color is red and there is css file in custom layout that says, in this layout link color is green.

Then again, this proposal is not very good. There is no way for themer/sitebuilder to change css order of all files from theme and from custom layouts anyway.

Adding 'css group' to plugin array could be an option, but it is probably not worth it, as this is edge case and still will not allow to order all css files in theme.