1

I have a Drupal 8 module with the following section in the file flot_d8.libraries.yml

flot:
  version: 1.x
  css:
    component:
      css/flot.css: {}
  js:
    lib/jquery.flot.js: {}
    js/flot_d8.js: {}
  dependencies:
    - core/jquery
    - core/drupalSettings

I have another module which is an optional dependency of flot. It does not need to be present, but if it is, it needs to be included in the dependencies section. So I need to add the line - timezone_js/timezone_js at the end...or, more likely, add the equivalent entry to the array that this yml file gets converted into.

Is there a way that one module can alter the assets of another module when it is installed?

I seems like I ~could~ just hard-code the line in myself, but I would like other people to be able to extend the flot module, without me having to add new dependency lines for every add-in.

Similarly, the Flot module has an element with a #pre_render function. Is there a way that a module can add an entry to the pre_render array of another module?

1
  • hook_library_info_alter
    – user21641
    Mar 9, 2016 at 23:10

1 Answer 1

2

My flot plugin is called timezone_js. I created a file, timezone_js.module and added a call to hook_library_info_alter.

function timezone_js_library_info_alter(&$libraries,$extension){
  //We need to add this module as a dependency of the flot module.
  if ($extension == "flot_d8") {
    $libraries['flot']['dependencies'][] = 'timezone_js/timezone_js';
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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