Problem/Motivation
If a developer is adding a CSS library, and forgets to nest the assets under one of the existing categories (component
, theme
, etc), the following error is thrown:
Error: Cannot use assign-op operators with overloaded objects nor string offsets in Drupal\Core\Asset\LibraryDiscoveryParser->buildByExtension() (line 138 of core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php).
this happens, for instance, with the following (incorrect) code in foo.libraries.yml
:
bootstrap-cdn:
remote: http://getbootstrap.com
version: 3.3.6
license:
name: MIT
url: https://github.com/twbs/bootstrap/blob/master/LICENSE
gpl-compatible: false
css:
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css: { type: external, minified: true }
js:
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js: { type: external, minified: true }
dependencies:
- core/jquery
Note the CSS needs to be nested like so:
...
css:
theme:
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css: { type: external, minified: true }
Proposed resolution
Add an assertion to make sure $options
is an array.