5

In my theme's libraries.yml file, after the global-styling section, i'm trying to replace one JavaScript file from the core Toolbar module (it's addition of padding-top to body interferes with our theme, so just changing that to margin-top).

libraries-override:
  toolbar/toolbar:
    js:
      js/views/BodyVisualView.js: js/views/BodyVisualView.js

I repeatedly get the error:

Drupal\Core\Asset\Exception\IncompleteLibraryDefinitionException: Incomplete library definition for definition 'libraries-override' in extension 'mythemename' in Drupal\Core\Asset\LibraryDiscoveryParser->buildByExtension() (line 93 of /vagrant/web/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php).

21

The answer is simply that the libraries-override definition must go in the .info.yml not .libraries.yml:

So in mythemename.info.yml:

libraries:
  - mythemename/global-styling
libraries-override:
  toolbar/toolbar:
    js:
      js/views/BodyVisualView.js: js/views/BodyVisualView.js

If placed logically there, alongside the libraries definition, it works perfectly.

Note that the second 'toolbar' is the library name from toolbar.libraries.yml, other library names in there include toolbar.menu, so if overriding a file from there it would be "toolbar/toolbar.menu:" instead of "toolbar/toolbar:".

4
  • 2
    I updated drupal.org/theme-guide/8/assets to be a bit clearer about both files in contributed modules and the location of the override definition itself.
    – mlncn
    May 8 '16 at 16:19
  • 2
    What to do if the module / theme has no own libraries? I tried putting an empty library in info.yml but that does not include the override.
    – ñull
    Sep 12 '18 at 12:39
  • 1
    @ñull you may, but do not need to, define a library in a mythemename.libraries.yml file. As long as the target path given is relative to your theme root, you can make this override work just by creating the one overriding file, and the above (minus the 'libraries' section) in your *.info.yml.
    – mlncn
    Sep 14 '18 at 0:54
  • When the library name contains a dot just use the full name like so libraries-override: lightgallery/lightgallery.load:
    – undersound
    Dec 15 '19 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.