Scenario: my client has a tight server environment where the server cannot communicate to the internet except to serve pages on port 443 and port 80. (so there's nothing in the server dns cache and port 53 out is blocked)

In this case, CDNs only work for the client, not for the server.

This bug occurs after 3.17 , so 3.18 and higher.

Workaround/Solution:
Add this patch which adds the missing drupal-bootstrap.min.css and also a missing less file that is otherwise provided by server side cdn which doesn't work for servers that cannot access the internet other than serving 443 and 80.

This particular client is using IIS on Windows.

The patch does the job, see the patch.

Comments

joseph.olstad created an issue. See original summary.

joseph.olstad’s picture

joseph.olstad’s picture

markhalliwell’s picture

Title: patch for when High security server setups are unable to use CDNs » Warning: Illegal string offset 'name' in DrupalBootstrapStyles
Assigned: joseph.olstad » Unassigned
Priority: Major » Normal
Status: Needs review » Needs work

This seems like a backwards solution (and honestly complete overkill) to the actual error you've encountered:

Warning: Illegal string offset 'name' in Drupal\bootstrap\Plugin\Provider\DrupalBootstrapStyles->Drupal\bootstrap\Plugin\Provider{closure}() (line 71 of themes\bootstrap\src\Plugin\Provider\DrupalBootstrapStyles.php 

Also, this project has never and will never commit 3rd party (i.e. upstream Bootstrap CSS) to its codebase.

markhalliwell’s picture

A simple empty($file['name']) || prepended to the if statement would likely suffice.

https://git.drupalcode.org/project/bootstrap/blob/8.x-4.x/src/Plugin/Pro...

      if (strpos($file['name'], '/dist/' . $version . '/' . Bootstrap::PROJECT_BRANCH . '/') !== 0) {
joseph.olstad’s picture

@markcarver, my clients servers port 53 out is blocked, so dns is not working , so the server side cannot get any cdn content

PS, it was really tough figuring this out because the TTL values in the ProviderInterface.php are very high, so somewhere these values are cached and a simple cache rebuild will not flush them out. I even deleted the tmp directory and tried to find the files in sites/default/files/? not sure where these values get cached didn't have time to look close enough at the code, so in a code blitz to power through, I set all the TTL values to 0 in the ProviderInterface.php in order to have that part of the code execute where it's trying to go out to the cdn.

Due to supporting servers that have no port 53, I would much prefer that this cdn logic was moved to the front-end so that the requests to the cdns is all done on the front end and not from the back end.

joseph.olstad’s picture

the undefined index issue is merely a symptom of a server that doesn't have access to request dns resolution of cdn names

The other reported issues were on IIS servers, this might affect other environments if you flush all the cached values set TTL to 0 and kill port 53 out on the server asuming also the said server is not also a dns server with cached dns values.

also to test would have to maybe flush dns cache on the server after blocking port 53 out.

joseph.olstad’s picture

Issue summary: View changes
markhalliwell’s picture

Category: Feature request » Support request
Status: Needs work » Closed (works as designed)

https://drupal-bootstrap.org/api/bootstrap/docs!Theme-Settings.md/group/...

Just set the following in your sub-theme then: cdn_provider: ''

Then manually inject the link and script tags in your sub-theme's html.html.twig file that point to the specified CDN URLs you want.

No need in attempting to use the CDN provider system if your server can't even access it.

joseph.olstad’s picture

Title: Warning: Illegal string offset 'name' in DrupalBootstrapStyles » A checkbox to enable or disable server side cdn and add a cdn to theme.
Category: Support request » Feature request
Status: Closed (works as designed) » Active

ok thanks for the tip, however we will still need a patch to fix the undefined index no?

or does setting cdn to '' in the sub theme get rid of any requests on the server end?

maybe a checkbox setting for bootstrap to turn on or off this.?

joseph.olstad’s picture

Assigned: Unassigned » joseph.olstad
Status: Active » Needs work

anyhow thanks for your tips, I'll see if I can come up with a helpful patch.

markhalliwell’s picture

Title: A checkbox to enable or disable server side cdn and add a cdn to theme. » Warning: Illegal string offset 'name' in DrupalBootstrapStyles
Assigned: joseph.olstad » Unassigned
Category: Feature request » Support request
Status: Needs work » Closed (works as designed)

we will still need a patch to fix the undefined index no?

No. As you stated, this is really just a symptom of a very specific nature. I think it would rather make more sense to keep this error so it's searchable and people can come to this issue and see what's going on.

In reality, it should have never gotten that far (still not sure how it did) because it would mean that that URL returned had a valid "files" property inside a JSON object that was successfully decoded.

maybe a checkbox setting for bootstrap to turn on or off this.?

There's already a select option in the dedicated "CDN (Content Delivery Network)" theme settings tab, where you can simply set the CDN Provider to "None".

joseph.olstad’s picture

ok sounds good, thanks for your assistance and great work on this.

joseph.olstad’s picture

*** EDIT ***

I will test the option 'none' see what happens.

joseph.olstad’s picture

When I choose the option 'none' (compile locally) , it sounds like I have to compile something

from the docs:

If you need
to customize Bootstrap, you must compile the [Bootstrap Framework] source code
locally and disable the
[`cdn_provider` theme setting](<!-- @url theme_settings#cdn_provider -->).

I'm guessing, but it seems like to get the compiled resources I would have to choose the options from this webform from:
https://getbootstrap.com/docs/3.4/customize/

then download and copy them to the css folder

such as vendor-prefixes.less and bootstrap.min.css?

in order to test this I guess I'd have to disconnect my dev servers from the internet as are my clients servers or have a local copy running disconnected from the web.

joseph.olstad’s picture

Here is patch 2 rerolled for HEAD of 8.x-3.x

Patch 2 is for bootstrap 8.x-3.21
patch 16 is for bootstrap 8.x-3.23

This is an edge case for servers that have no CDN access, crash otherwise.

IMHO, it should only be the client that uses CDN, not the server.

jonathanvarunbenjamin’s picture

how do we install the patches?

joseph.olstad’s picture

@jonathanvarunbenjamin

have a look at your composer.json file for your project in the root of your drupal project and add a line for drupal/bootstrap something similar to this example:

"extra": {
  "patches": {
    "drupal/core": { "<patch1 information>": "<patch1 file path>" },
    "drupal/libraries": { "<patch1 information>": "<patch1 file path>",
    "drupal/bootstrap": { "Illegal offset fix in DrupalBootstrapStyles": "https://drupal.org/files/issues/2020-10-18/bootstrap-provide_missing_css-3113579-16.patch"
   }
  }

once you have done this run composer install
assumes you have composer installed correctly.

https://www.youtube.com/watch?v=PF8eDim7Wts

Holka_a’s picture

My bad refer below patch

Holka_a’s picture

StatusFileSize
new19.36 KB

Patch for D10 compatible version of bootstrap.