Problem/Motivation

Upgrading to Drupal 10.1 with a composer update appears to break Bootstrap subthemes.

Steps to reproduce

Take a Drupal 10.0.9 site with a bootstrap subtheme.

run composer update. drupal/core updates, as does drush/drush (to 11.6.0) and twig/twig to (v3.6.1) amongst others. drupal/bootstrap does not update.

run drush cex

Commit changes to branch, deploy to server using composer install, drush deploy, which run without error.

Bootstrap themes now throw error 500s while viewing css pages, with the following error:

Location: https://(mysite)/sites/default/files/css/css_aDnKtgHZotl886lNpw2m2AMaIQMNzPogjbqqHmIdB5o.css?delta=3&include=eJxdjlEOgzAMQy-E4EwpjVirgLMkTOP200Y1FT799OLYDw9ep0TOwwzjqT53tmNIQHgY6aRQvNg6EoBE0dPPtivJqIbF2P2E2OZWF5QSJWlJQLn65TBzwv7XG6RK76tVXIXupeM5dvRHWS964wovUbB121dkki7nQoLl9uuLfhs-CDBuSA&language=en&theme=(mytheme)

Error: Class "Drupal\bootstrap\Bootstrap" not found in include_once() (line 31 of (sitedir)/web/themes/contrib/bootstrap/bootstrap.theme).

Disabling CSS/JS aggregation resolves the issue, but re-enabling CSS/JS aggregation breaks the Bootstrap theme again.

I can force Drupal to get around these errors and display the css file without throwing a 500 error by running a "drush cr" then loading ONLY ONE css file directly. But I need to clear the cache before loading each aggregated css file.

I'd say this is a fluke, it *feels* like a file permission problem, but this is now the third D10.0.9 site with a bootstrap subtheme site I've had this happen to this evening.

If I revert to the previous branch: git checkout HEAD~1 && composer install - bootstrap works fine again.

I'm going to leave this one dev site broken to see if we can gather more data. Anything I should look at next?

Issue fork bootstrap-3369979

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

TrevorBradley created an issue. See original summary.

pick_d’s picture

I have the same issue with Drupal 10.1 and this theme.

However, in my case disabling advagg and built-in aggregation doesn't really solve the issue completely for some reason.
Theme still won't work properly, but it is "way less broken". Maybe I messed up somewhere else. With D9.5 everything works just fine.

SITE/sites/default/files/js/js_sMSIP1zYFriunMpQD3CnuzLA2MwAy8fDHkEZOuIC4TU.js?delta=0&include=eJx9UQtuwyAMvRANZ9hJIkOshBZiZpuq2ekHy2dNp1WKYvOe7eePJ0Z7_SzIi3Hgb71S_bJ98vur_EspPtT4VmPgkiF2mWlkFKng3MgCcad-kUsM801MhK_Ftp-RRRRTrSxo0uLUjpFcjRPPIaucMV1q-nhSBa_hjj9lTZVodqe2p3FEKsqQbaZMd-QnRImihmymIEq8WMjh8BPw7QJyYYThpDkEyRE8rqCCc-AidusuO5lCOoVveCYJGmh-KQWRxg6u8DCtFwdsN9slnMsreJ69KHlKOaKigSGFud_CekFgP9nVmCLIe1Lzu1AvImutUE_DcyVkwjwhD1WyNL3Cx8IP5CTfBq9sghlG5Pdn39s_d9msHPO2poxMxOqL7jX29znzyFFGfEN1U7t3G3HWP_tF8ZDxoyUbF8Y-h4x2d74BGUk3oQ&language=ru&scope=footer&theme=mybt

Error: Class "Drupal\bootstrap\Bootstrap" not found in include_once() (line 31 of SITEDIR/web/themes/contrib/bootstrap/bootstrap.theme).

trevorbradley’s picture

@pick_d - heads up that bootstrap 3.28 works great on Drupal 10.0.9 if you want to get started on the D10 major upgrade. Fix the version: "composer require drupal/core-recommended:10.0.9".

I would caution against a D10.1.0 upgrade until we figure this out.

Annoyingly, I can't replicate this on my lando local - it works great with aggregated CSS. Investigating.

pick_d’s picture

Thanks, will try that with 10.0.9.

trevorbradley’s picture

There are entries in the D10.1.0 changelog that imply D10.1 handle building css and js aggregation differently. See: https://www.drupal.org/node/2888767

Basically the theme file is failing to load the library with "use Drupal\bootstrap\Bootstrap;". The use command is there but it can't find it. But my contrib *.module files similarly use "use" statements with no issues.

What bugs me is the fact that this is working on my local (after I turned on caching and re-enabled css/js aggregation) but failing on my deployed dev server. There are small mismatches in apache, php, mysql versions and some libraries, but nothing that quite adds up.

"drush cr" kind of kicks it in the pants, but not enough. It's the oddest behaviour.

I'll think about this and see what I come up with tomorrow.

la558’s picture

I'm experiencing the same problem.
After upgrading to Drupal 10.1.0, Bootstrap theme breaks when 'Bandwidth optimization' for 'CSS' and 'JS' files are checked to 'aggregate'
When aggregation is not selected, the theme loads just fine.
If switching to another theme, such as 'Claro' the interface displays without any issue.

bailsbails’s picture

Also seeing this on multiple sites. Have tried changing the nginx config as suggested https://www.drupal.org/node/2888767#nginx-php-fpm
But even then bootstrap css js agg fails to create any files.
This is becoming a big issue for us (100+ sites).

mademo made their first commit to this issue’s fork.

klemendev’s picture

Could also be this: https://www.drupal.org/project/drupal/issues/3368769 (not directly related to original issue, but for the ones having problems only when aggregation is enabled this may also be the culprit).

However if class loading errors are logged, the link above will not help.

trevorbradley’s picture

@KlemenDEV: Two pieces of evidence that contradict the nginx/PHP-FPM theory:

1) This is happening to me on apache.
2) This isn't happening on other themes like Claro.

klemendev’s picture

However if class loading errors are logged, the link above will not help.

My comment was more as some may land here but in fact have the other problem (or both problems combined).

tikaszvince’s picture

My workaround for this is to add the autoload lines to my project's composer.json
The path should point to the proper place of bootstrap/src

  "autoload": {
    "psr-4": {
      "Drupal\\bootstrap\\": "www/themes/bootstrap/src"
    }
  },
rishi.kulshreshtha’s picture

As mentioned by @TrevorBradley on #3, locking Drupal to composer require drupal/core-recommended:10.0.9 works without any issues.

@tikaszvince, I'll try your solution soon.

bsuttis’s picture

I had the same problem this morning deploying to Acquia PROD. No issues on DEV or STG but after deployment to PROD I began to get 503s and this log: Error: Class "Drupal\bootstrap\Bootstrap" not found in include_once() (line 31 of .../themes/contrib/bootstrap/bootstrap.theme)

@tikaszvince, your workaround fixed the issue in my case as well, thanks.

It seems like a race condition to me. When I was testing, I was visiting /user and /user/register and sometimes they'd work and other times were a 503.

trevorbradley’s picture

Title: Drupal 10.1 breaks Bootstrap subthemes » Drupal 10.1 breaks Bootstrap
Priority: Normal » Major

I tried tackling this again this evening, without much headway. I did determine a few things:

1) This isn't a bootstrap subtheme issue. The same error 500 occurs on both subthemes and bootstrap.

2) Full stack trace for anyone who can decipher what might be happening:

The website encountered an unexpected error. Please try again later.

Error: Class "Drupal\bootstrap\Bootstrap" not found in include_once() (line 31 of themes/contrib/bootstrap/bootstrap.theme).
Drupal\Core\Extension\Extension->load() (Line: 137)
Drupal\Core\Theme\ThemeInitialization->loadActiveTheme() (Line: 74)
Drupal\Core\Theme\ThemeInitialization->initTheme() (Line: 150)
Drupal\system\Controller\AssetControllerBase->deliver()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 166)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)

I'm going to bump this up to Major - obviously something is bootstrap specific and clashing with the 10.1 update.

trevorbradley’s picture

Possibly related to: https://github.com/drupalprojects/bootstrap/blob/8.x-3.x/autoload-fix.php ?

Why does bootstrap need an "autoload-fix.php" in the first place? Anyone know the history of this? Could this fix finally have broken?

There's a function _find_autoloader() in scripts/bootstrap.php that makes reference to Drupal 8 - I'm wondering if this mechanism needs a tuneup.

kevinfunk made their first commit to this issue’s fork.

shelane’s picture

I just used the upgrade status module to scan the Bootstrap theme and I get these errors for D10 readiness and I'm not sure if any of them would be related to this issue.

File name Line Error
themes/custom/bootstrap/src/Plugin/Alter/ThemeRegistry.php 21 Class Drupal\bootstrap\Plugin\Alter\ThemeRegistry extends @internal class Drupal\Core\Theme\Registry.
themes/custom/bootstrap/src/Plugin/ProcessManager.php 81 Call to deprecated method getInlineElementTypes() of class Drupal\bootstrap\Plugin\ProcessManager. Deprecated in bootstrap:8.x-3.21 and is removed from bootstrap:8.x-4.0. This method will be removed when process managers can be sub-classed.
themes/custom/bootstrap/src/Plugin/Provider/ProviderBase.php 212 Call to deprecated method getAssets() of class Drupal\bootstrap\Plugin\Provider\ProviderBase. Deprecated in 8.x-3.18, will be removed in a future release.
themes/custom/bootstrap/src/Plugin/ProviderManager.php 70 Call to deprecated method processDefinition() of class Drupal\bootstrap\Plugin\Provider\ProviderInterface. Deprecated in 8.x-3.18, will be removed in a future release. There is no replacement for this functionality.
themes/custom/bootstrap/src/Plugin/Setting/Advanced/Cdn/CdnProvider.php 273 Call to deprecated method getApi() of class Drupal\bootstrap\Plugin\Provider\ProviderInterface. Deprecated in 8.x-3.18, will be removed in a future release. There is no replacement for this functionality.
themes/custom/bootstrap/bootstrap.libraries.yml 0 The 'modal.jquery.ui.bridge' library is depending on a deprecated library. The "core/jquery.ui" asset library is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3067969
themes/custom/bootstrap/bootstrap.libraries.yml 0 The 'modal.jquery.ui.bridge' library is depending on a deprecated library. The "core/jquery.ui.widget" asset library is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3067969
themes/custom/bootstrap/bootstrap.libraries.yml 0 The 'modal.jquery.ui.bridge' library is depending on a deprecated library. The "core/jquery.ui.draggable" asset library is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3067969
themes/custom/bootstrap/bootstrap.libraries.yml 0 The 'modal.jquery.ui.bridge' library is depending on a deprecated library. The "core/jquery.ui.mouse" asset library is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3067969
themes/custom/bootstrap/bootstrap.libraries.yml 0 The 'modal.jquery.ui.bridge' library is depending on a deprecated library. The "core/jquery.ui.position" asset library is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3067969
themes/custom/bootstrap/bootstrap.libraries.yml 0 The 'modal.jquery.ui.bridge' library is depending on a deprecated library. The "core/jquery.ui.resizable" asset library is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3067969
bootstrap.info.yml 0 The 'image_widget_crop/cropper.integration' library is not defined because the defining extension is not installed. Cannot decide if it is deprecated or not.
hosterholz’s picture

Status: Active » Reviewed & tested by the community

Tested MR !29. Works.

joseph.olstad’s picture

@shelane, your scanning tool appears to be looking at custom code. Someone on your team probably included a very old copy of bootstrap as custom code in your build.

You should grab the latest version of bootstrap, it is already functional for Drupal 10.0.9

This issue currently is looking at Drupal 10.1.0 compatibility.

trevorbradley’s picture

I get that this solution does work... but why does it work? I'm a little cautious about a solution where we don't understand the root problem.

I see that this change adds the following to autoload_psr4.php and autoload_static.php:

$ diff site_fixed/vendor/composer/autoload_psr4.php site_old/vendor/composer/autoload_psr4.php 
68d67
<     'Drupal\\bootstrap\\' => array($baseDir . '/web/themes/contrib/bootstrap/src'),
$ diff site_fixed/vendor/composer/autoload_static.php site_old/vendor/composer/autoload_static.php 
119d118
<             'Drupal\\bootstrap\\' => 17,
384,387d382
<         ),
<         'Drupal\\bootstrap\\' => 
<         array (
<             0 => __DIR__ . '/../..' . '/web/themes/contrib/bootstrap/src',

But other themes like claro don't even have a composer.json file.

I would have guessed this has something to do with bootstrap's slight of hand tricks with autoload, but I'm still really unclear why this is working fine without the autoload fix on my lando local but not working on my production sites.

I really don't want to delay a working fix though.

ilfelice’s picture

Howdy,

I tried the workaround noted in #12, but it did not work. I still get the following error when CSS/JS aggregation is enabled:

Error: Class "Drupal\bootstrap\Bootstrap" not found in include_once() (line 31 of /var/www/html/web/themes/contrib/bootstrap/bootstrap.theme).

The theme does work fine when CSS/JS aggregation is disabled. FWIW, my running environment is as follows:

- Drupal 10.1.0
- Ubuntu 22.04 server
- Apache/2.4.52
- PHP version 8.1.20
- Bootstrap 3 theme + sub-theme

2dareis2do’s picture

I have the same or similar issue when updating to 10.1 (and 10.1.1) when using nginx as a reverse proxy in front of an apache web server when enabling css and js aggregation. Switching theme to Oliveiro and the issue goes away.

e.g.

Error: Class "Drupal\bootstrap\Bootstrap" not found in include_once() (line 31 of /var/www/vhosts/mydomain.com/httpdocs/web/themes/contrib/bootstrap/bootstrap.theme).

catch’s picture

But other themes like claro don't even have a composer.json file.

They don't have a composer.json file and they don't ship any OOP code. I'm not aware of any themes other than bootstrap that do, which might be why it's hitting this problem.

2dareis2do’s picture

StatusFileSize
new552 bytes

Uploading patch here as I can't see it already

2dareis2do’s picture

Tried patch but does not seem to help in my scenario i.e. running apache with nginx working as reverse proxy

2dareis2do’s picture

https://www.drupal.org/project/bootstrap_barrio also has composer.json file

Seems to behave in a similar way

In fact every theme I have seen installed via composer seems to have composer.json?

2dareis2do’s picture

This also looks similar to a couple of closed issues e.g devel module https://www.drupal.org/project/devel/issues/2853398 and webform_bootstrap https://www.drupal.org/project/webform/issues/2893225

2dareis2do’s picture

With regards to:

Why does bootstrap need an "autoload-fix.php" in the first place?

Looking at the autoloadFixInclude method it states:

 /**
   * Returns the autoload fix include path.
   *
   * This method assists class based callbacks that normally do not work.
   *
   * If you notice that your class based callback is never invoked, you may try
   * using this helper method as an "include" or "file" for your callback, if
   * the callback metadata supports such an option.
   *
   * Depending on when or where a callback is invoked during a request, such as
   * an ajax or batch request, the theme handler may not yet be fully
   * initialized.
   *
   * Typically there is little that can be done about this "issue" from core.
   * It must balance the appropriate level that should be bootstrapped along
   * with common functionality. Cross-request class based callbacks are not
   * common in themes.
   *
   * When this file is included, it will attempt to jump start this process.
   *
   * Please keep in mind, that it is merely an attempt and does not guarantee
   * that it will actually work. If it does not appear to work, do not use it.
   *
   * @see \Drupal\Core\Extension\ThemeHandler::listInfo
   * @see \Drupal\Core\Extension\ThemeHandler::systemThemeList
   * @see system_list
   * @see system_register()
   * @see drupal_classloader_register()
   *
   * @return string
   *   The autoload fix include path, relative to Drupal root.
   */

See also Document differences between themes and modules and their limitations https://www.drupal.org/project/bootstrap/issues/2770001

Namespacing/Autoloading - Generally this works just fine for themes since anything in {system} will automatically add the namespaces to the autoloader. That being said there is a small caveat, generally when dealing with cross-request/ajax theme class based callbacks, that prevent the namespaces from being registered in themes when logic is being processed too early in a low level bootstrapped request. This is why I added the Bootstrap::autoloadFixInclude helper method so autoload-fix.php can be included as a "file" for certain callbacks where it's necessary.

gurunathan’s picture

The patch didn't resolve the issue.

shelane’s picture

Status: Reviewed & tested by the community » Needs work

Given reports that the patch is not working, I'm setting back to "Needs work."

joseph.olstad’s picture

****EDIT****
Hmm, looks like a variety of possible solutions available here, not sure which is best.

@shelane, patch 26 looks like a likely candidate to go in, it's a chicken and egg thing with composer.

Any heavy hitters want to weigh in on this?
****EDIT****

hosterholz’s picture

You cannot use composer-patches to make changes to the autoloader. See Non-patchable targets. The patch needs to be applied before the installation.
What you need to do is install the theme from the Issue-Repository including the changes to composer.json:

composer config repositories.bootstrap-3369979 git https://git.drupalcode.org/issue/bootstrap-3369979.git
composer require drupal/bootstrap:dev-3369979-drupal-10.1-breaks
catch’s picture

Status: Needs work » Needs review

Yes #34 is right, just applying the patch to the module does nothing. You might be able to run composer dump-autoload to get the autoload changes picked up without having to make the composer.json changes though.

I think that's probably the right fix for bootstrap so moving back to needs review. I don't use bootstrap so not in a position to test it.

The existing core issue if anyone want to try to help there is #2941757: Extension System, Part IV: Properly register all installed extensions/namespaces during container generation

2dareis2do’s picture

Hiding patch as is a non patchable target

dubois’s picture

Change to composer.json does the trick. As @hosterholz says using issue-fork is required given the nature of the change. `composer dump-autoload` did not work on our site using bootstrap sub-themes.

2dareis2do’s picture

Thank you @hosterholz

Adding repository via composer config and specifying branch with composer require, patch appears to be now working now i.e css and js is now showing with aggregation enabled.

catch’s picture

Status: Needs review » Reviewed & tested by the community

I think that's enough manual testing to mark this RTBC.

2dareis2do’s picture

Just to clarify the above works for me when running apache with nginx reverse proxy e.g plesk webserver setup

I am still having a problem with css and js aggregation when running nginx locally using wodby stack

I have tried loading additional config using

NGINX_SERVER_EXTRA_CONF_FILEPATH: /var/www/html/locations.conf

and in locations.conf I have

# Passes image style and asset generation to PHP.
location ~ ^/sites/.*/files/(css|js|styles)/ {
  try_files $uri @rewrite;
}

I have also tried as absolute paths e.g.

location ~ /var/www/html/web/sites/.*/files/(css|js|styles)/ {
  try_files $uri @rewrite;
}

I am not sure how to test nginx to see if this additional directive is being applied, but previously I had Drupal 10 running without issue on Wodby stack running nginx without having to add any location directive.

This is different from the issue here as server generates a 404 rather than a 500 error as seems to affect contrib themes.

To get around this I have switched to running Apache on my local.

2dareis2do’s picture

StatusFileSize
new148.98 KB
2dareis2do’s picture

Added separate issue for broken css and js when enabling aggregation for contrib themes

https://www.drupal.org/project/drupal/issues/3373929

  • shelane committed 131d5e1b on 8.x-3.x authored by kevinfunk
    Issue #3369979 by 2dareis2do, kevinfunk, mademo, TrevorBradley, catch,...
shelane’s picture

I will be tagging a release with this MR included. I'm going to leave the issue open for a while and see what else (if anything) might be reported on it. I will also keep an eye on the related core issue that @2dareis2do reported. I have marked that as related here. Thanks everyone.

pick_d’s picture

Thanks a lot.

Latest -dev version works with D10.1.1 for me.

The only issue I noticed so far is the following warning that sometimes pop up during 'drush updb' or 'drush cr':

 [notice] The file assets://css was not deleted because it does not exist.
 [notice] The file assets://js was not deleted because it does not exist.

(I use 'bootstrap CDN' option in theme settings, but custom links point to files stored locally, if that is relevant)

catch’s picture

@pick_d that notice is harmless, but it might be worth a minor core bug report to suppress it.

pick_d’s picture

@catch
Thanks.

Can't reproduce it now. Maybe it's related to advagg somehow (which I uninstalled as it has issues upon upgrade, while in the same time D10.1 bundles and minifies css and js surprisingly well now). So no info to file a bug.

Anyhow, thanks for your time.

joseph.olstad’s picture

Looking forward to testing this with D10.1.x . Ya so as I suspected but was hesitant to suggest as a fix because it seems there may be multiple fixes for this, patching the json file doesn't help at all, The composer.json change had to be committed to the release for composer workflows to function normally. Otherwise a composer circus has to be drummed up using tricks from deep in the instruction manual of composer that are helpful but it's a lot nicer just doing a composer up and getting the fix.

joseph.olstad’s picture

@shelane, no major issues, I think we can tag a release anytime!

joseph.olstad’s picture

Version: 8.x-3.28 » 8.x-3.29
Status: Reviewed & tested by the community » Fixed

NVM, @Shelane, thanks, you already tagged 3.29, we're good to close this as "Fixed"

Status: Fixed » Closed (fixed)

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

kyber’s picture

So. What's the verdict on this one? Is bootstrap now only installable using composer?
After reading through it fairly carefully, it *seemed* that generating the vendor/autoload.php using composer dump-autoload should be sufficient, and the result could then be packaged up.

However, we are still encountering this issue in the latest release, but only with a subtheme.

Specifically that:
sites/default/files/css/css_XXXXX.css?theme=bootstrap
loads the aggregated CSS, but
sites/default/files/css/css_XXXXX.css?theme=custom_subtheme
fails, with aggregation enabled, with the 'Class "Drupal\bootstrap\Bootstrap" not found in include_once() (line 31 of themes/contrib/bootstrap/bootstrap.theme)'

Now, we don't particularly need aggregation, it just complicates debugging and editing, is a bit user unfriendly, and in this age of HTTP2 and compression, doesn't really offer any significant benefits.

But, I'm a bit concerned this might be revealing other problems with bootstrap in general compared to other themes.
It could be an issue with the subtheme itself and needed D10 changes though?

kyber’s picture

Ok... what does make this work with subthemes is running the composer update against all of the drupal instance... which pulls the bootstrap into the global autoload.

Only... we were trying to keep bootstrap inside its own folder and not taint things outside it, so need to find another way to do this.

But that could explain why comments above said that composer dump-autoload was not working with subthemes. Perhaps the bootstrap vendor/autoload.php isn't even being called in that case, and the only way to get our theme to call it is to have those includes in the main drupal autoload?

kyber’s picture

Ok... it turns out my composer attempts had all in fact failed, I was just thrown off by cache clear sequences when switching between aggregated and not.

I did find a horrendous hack that works "reliably" with our subtheme.
1) run composer dump-autoload in the bootstrap theme - this generates the vendor/autoload.php which IMO bootstrap should be including the release tar.gz already (zipped up it's 5K, but I can't attach that to a comment).
2) edit bootstrap.theme and add:
require_once('/var/www/html/sitename/themes/contrib/bootstrap/vendor/autoload.php');
at the top

I'm sure there must be a better method than a hardcoded pathname, but relative path did not work with however drupal was calling it.

I'm open to more ideas, but for now I'll just document this for our stuff.

joseph.olstad’s picture

Did you try this?
composer require drupal/bootstrap:"^3.29"

if this causes an error, look at
composer why drupal/bootstrap
(figure out and resolve)

then rebuild drupal caches?

kyber’s picture

Trying not to get too much in the weeds on composer, this was going to prod as .tar.gz snapshot.
So far that is still something that works pretty consistently everywhere except with bootstrap theme.

But I'll give that a try in dev, just to see what it does.

joseph.olstad’s picture

your composer.json and composer.lock should normally be included or added to git for your project if they aren't already.

kyber’s picture

I'm maintaining a theme created sometime prior as part of a larger site. The creator chose to extend bootstrap for the theme. None of the other modules nor the theme are being maintained by composer, and the theme did not have any composer additions. Everything is being deployed using the extension/drupal release tarballs, pretty much same process as drupal had used throughout its history.

The fix in this bug, which was not bundled into the bootstrap release tarball as a vendor/autoload.php for some reason (IMO it should be just like those pieces are bundled as part of the drupal release tarballs) I had to generate myself, and did not fix the theme, nor did a few other things I tried with it.

So, I put in the hack above to get things working. Really bootstrap is rather unusual compared to other drupal themes in what it seems to be trying to do load-wise, and the "autoload-fix.php" is rather worrying, but, yeah, not something I created, just trying to keep it chugging along with minimal impact.

That said, I'm willing to try seeing if pulling things in composer magically fixes things in dev, but am mildly skeptical given the issue seems to be that the autoload I generated was not being invoked at all when bootstrap gets pulled in by the subtheme when drupal was doing the aggregation. And, yeah, only going to do it in dev, and it will require quite a few changes to make that work, ones I'm not interested in doing in prod, but it's worth trying as an experiment..

kyber’s picture

Oh! Running composer is NOT necessary.
The vendor autoload is indeed included in the release tarball!

So the ONLY change necessary to fix the issue with subthemes + CSS aggregation is:
require_once('/var/www/html/sitename/themes/contrib/bootstrap/vendor/autoload.php');
in the bootstrap.theme
Which is a silly hack but whatever.

Just recording this for anyone else in same situation.

stooit’s picture

We have customers who operate in an environment where themes cannot be installed via composer, so relying on autoloader is not possible.

To resolve we have been applying a hotfix which just adds an include to the top of bootstrap.theme, we haven't spotted any issues (yet):
require_once('src/Bootstrap.php');

2dareis2do’s picture

We have customers who operate in an environment where themes cannot be installed via composer, so relying on autoloader is not possible.

Crazy that Drupal developers can not run composer in this day and age.

I do not run composer on a prod environment, but make sure to include and changes to composer including vendor/composer/installed.php files in any git commits.

kyber’s picture

Thanks for your suggestion! I'll try that instead of my current hardcoded absolute path hack. I think I'll retest require_once('vendor/autoload.php'); too... that's more likely to pull in other things that could be needed.

And, yeah, I don't see why installing all of drupal with composer should be necessary. Bootstrap theme does some weird stuff other themes don't do, and maybe generating that just pulls more things into global autoload. Still kinda ew, esp depending on how bootstrap is removed.

IMO this is not indicative of "use moar composer" but rather of a design issue in drupal or bootstrap theme with subthemes, but have other priorities besides this, so I'll just use your hack.

kyber’s picture

Results of testing over here with a bootstrap subtheme and aggregated CSS/JS, clearing cache each time.

require_once('src/Bootstrap.php') WORKS
require_once('vendor/autoload.php') FAILS
require_once('/var/www/html/sitename/themes/contrib/Bootstrap/vendor/autoload.php') WORKS

jjancel’s picture

Hello
with require_once('src/Bootstrap.php')
I have the error:
core\includes\bootstrap.inc(164): _drupal_error_handler_real Undefined array key "url" in Drupal\Core\Asset\JsCollectionOptimizerLazy->optimizeGroup() (\core\lib\Drupal\Core\Asset\JsCollectionOptimizerLazy.php line 174)
for css
Warning: Undefined array key "url" in Drupal\Core\Asset\CssCollectionOptimizerLazy->optimizeGroup() (line 160 of core\lib\Drupal\Core\Asset\CssCollectionOptimizerLazy.php).
for javascript
Warning: Undefined array key "url" in Drupal\Core\Asset\JsCollectionOptimizerLazy->optimizeGroup() (line 174 of core\lib\Drupal\Core\Asset\JsCollectionOptimizerLazy.php).

jjancel’s picture

jjancel’s picture

This is caused by the libraries defined in bootstrap_library.libraries.yml not having the URL set with the licensing information.
see the solution:
https://www.drupal.org/project/bootstrap_library/issues/3380438

umac_de’s picture

This at #5 did the job for me.

4kant’s picture

Same as #67 (thanks for the hint):
https://www.drupal.org/project/bootstrap/issues/3257001#comment-15413771
Helped me too.