I am trying to use d3.js in my module, but I am facing some issues.
I have the D3 module installed in sites/all/modules/d3/ and d3.min.js installed in sites/all/libraries/d3/, and I can see the d3/examples fine.
Now I have a js script in my custom module that is supposed to use D3, but I fail to load it. Here's my attempt to load the library:
drupal_add_library('d3','d3');
# retrieve some data as JSON
$setting = mymodule_load_data($param);
# create the render array
$content = array(
'#attached' => array(
# attach JS
'js' => array(
array(
'type' => 'setting',
'data' => array('mymodule' => array('json_data' => $setting)),
),
array(
'type' => 'file',
'data' => drupal_get_path('module', 'mymodule') .'/js/myscript.js',
),
),
'css' => array(
drupal_get_path('module', 'mymodule') . '/css/mystyle.css',
),
)
);
# return result
return $content;
but I don't see d3 included in the source code of my page and myscript.js of course doesn't work.
I have checked the return value of drupal_add_library as suggested in the comments and it's FALSE.
Any hints?
drupal_add_library
returns a value. The library array, orFALSE
if the library wasn't found. Check the return value and post an update.hook_library_alter
in your module. The second argument$module
can be checked if it matchesd3
, if so, dump the$libraries
(first argument) to see what libraries this module declares (dpm()
if you have devel or justvar_dump()
). That might give you a clue on where you're going wrong.