Use case:

There is a sub-theme of bootstrap and the site build decides to develop a sub-theme of that sub-theme, simply to override some of the css. In such a case the override.min.css gets included after the theme css of the sub-theme and before the css of the sub-sub-theme.

However, it should be included before the css of the sub-theme.

The code:

In Drupal\bootstrap\Plugin\Alter\LibraryInfo::alter() which is triggered by the current theme (a.k.a. sub-sub-theme) the override.min.css gets added to

$libraries['theme']['css']['theme']

but it should be added to

$libraries['theme']['css']['base']

I'll post a patch in a minute.

CommentFileSizeAuthor
#2 better_location_for-2770613-2.patch717 bytesjurgenhaas

Comments

jurgenhaas created an issue. See original summary.

jurgenhaas’s picture

Status: Active » Needs review
StatusFileSize
new717 bytes
markhalliwell’s picture

Status: Needs review » Closed (works as designed)

Your sub-theme can alter the libraries if necessary, but I would say that your base/sub/sub-sub theme architecture needs some work so it only loads the overrides only once (unless I'm missing something here?), i.e.:

Base theme: Use CDN (loads overrides.min.css)
Sub-theme: Don't use CDN (doesn't load overrides.min.css as it's inherited from base theme)
Sub-sub-theme: Don't use CDN

Core should properly handle the weights based on the order of the library declarations in the theme ancestry.

markhalliwell’s picture

Status: Closed (works as designed) » Postponed (maintainer needs more info)

Sorry, wrong status.

jurgenhaas’s picture

Status: Postponed (maintainer needs more info) » Needs review

Well, here is what the current code base is producing:

Example 1 with sub-theme bootstrap_clean_blog, CDN enabled:

<link rel="stylesheet" href="//cdn.jsdelivr.net/bootstrap/3.3.5/css/bootstrap.css" media="all" />
<link rel="stylesheet" href="/themes/contrib/bootstrap/css/3.3.5/overrides.min.css?oao9k4" media="all" />
<link rel="stylesheet" href="/themes/contrib/bootstrap_clean_blog/css/clean-blog.css?oao9k4" media="all" />
<link rel="stylesheet" href="/themes/contrib/bootstrap_clean_blog/css/theme.css?oao9k4" media="all" />

This is the order of libraries/theme/base followed by libraries/theme/theme

The sub-theme has a chance to override certain thing from the base theme, including stuff in override.css

Example 2 with sub-theme bootstrap_clean_blog and sub-sub-theme bootstrap_fanom, CDN enabled:

<link rel="stylesheet" href="//cdn.jsdelivr.net/bootstrap/3.3.5/css/bootstrap.css" media="all" />
<link rel="stylesheet" href="/themes/contrib/bootstrap_clean_blog/css/clean-blog.css?oao9k4" media="all" />
<link rel="stylesheet" href="/themes/contrib/bootstrap_clean_blog/css/theme.css?oao9k4" media="all" />
<link rel="stylesheet" href="/themes/contrib/bootstrap/css/3.3.5/overrides.min.css?oao9k4" media="all" />
<link rel="stylesheet" href="/themes/custom/bootstrap_fanom/css/style.css?oao9k4" media="all" />

This is where the order gets confusing. The current theme (bootstrap_fanom) is looking for stuff in the base them and this is where override.css gets added to libraries/theme/theme. However, as bootstrap_clean_blog has added its own stuff to libraries/theme/theme already before, override.css suddenly gets output behind that. And now the overrides in bootstrap_clean_blog no longer apply.

From my point of view, overide.css belongs to libraries/theme/base always, no matter how many levels of sub-themes we're going to see. And I can not think of any downside when applying that change, it would work if bootstrap were on its own as well as in both samples given above.

  • markcarver committed 99065ce on 8.x-3.x authored by jurgenhaas
    Issue #2770613 by jurgenhaas: Better location for override.min.css if...
markhalliwell’s picture

Status: Needs review » Fixed

Thanks for the detailed information. That certainly helps clarify what you were talking about.

I went ahead and committed your patch with a few minor changes to help fix the documentation/comments around the code. I still credited you though since you came up with the patch. Thanks @jurgenhaas!

jurgenhaas’s picture

Thanks a lot @markcarver

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.