When defining a form using the form api I can attach my own css and js like this:

$form['#attached']['css'] = array(
    drupal_get_path('module', 'my_module') . '/my_css_file.css',
$form['#attached']['js'] = array(
    drupal_get_path('module', 'my_module') . '/my_js_file.js',

This page on Drupal.org suggests that we can attach system libraries the same way and gives this example:

$form['#attached']['library'][] = array('system', 'jquery.cookie');

However when I add this line to my form:

$form['#attached']['library'][] = array('ui.droppable');

Then the library does not get added.

If I go with the old method of:

drupal_add_library('system', 'ui.droppable');

Then is does get added.

What am I doing wrong?

1 Answer 1


Going from the working example, I imagine this is what you need:

$form['#attached']['library'][] = array('system', 'ui.droppable');

Without the module name Drupal won't know where to find the library hooks.

But if you want to add a custom library from sites/all/libraries/myAwesomeLibrary this is the right way:

$form['#attached']['libraries_load'][] = array('myAwesomeLibrary');

Your Answer

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

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