Hey guys,

I realize it'll be a while before the bugs are shaken out of Drupal 8 but I've been tinkering with some D8 module development and I discovered this warning when I invoke the libraries_info() function in my module.

It's a simple module and here's the basics of the .module file:


function mymodule_libraries_info() {	
  $libraries['mylibrary'] = array(
    'name' => 'My Library',
    'vendor url' => 'http://www.example.com',
    'download url' => 'http://www.example.com/downloads/',
    'version' => '2.05', 
    'files' => array(
        'js' => '/js/myjs.js',
	'css' => '/css/mycss.css',
    ),
  );
	  
	  return $libraries;
	
}

function mymodule_page_build(&$page) {
  	
	
  $path = libraries_get_path('mylibrary');

  $mylibrary = libraries_info('mylibrary'); // CAUSES THE WARNING
    
  $mylibrary_js = $path . $mylibrary['files']['js'];
  $mylibrary_css = $path . $mylibrary['files']['css'];
  
  $page['#attached']['js'][$mylibrary_js] = array('every_page' => TRUE);
  $page['#attached']['css'][$mylibrary_css] = array('every_page' => TRUE); 
  
  
}

The module works without any problem and I can see from spitting out the libraries objects that the libraries api is working too. It's just that warning that is showing up.

I'll see if I can find out what's going on and post back but I thought I would post a bug report in case someone else runs into the same issue.

Andrew

EDIT: I forgot to post the specifics of my Drupal 8 version etc....

8.0-dev (2013-9-27)
Libraries API 8.x-3.x-dev (2013-9-30)
PHP 5.4.12
MYSQL 5.1.67

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

awasson’s picture

Ok, just an update.
I think I have this handled... I'll submit a patch later today/tonight. I've found the same warning comes up in several places depending on what functions are called so I'll see if I can track them all down first and then create a patch.

EDIT (an update and the patch):
I'll upload the patch that goes against the Sept 30 2013 8.x-3.x branch because that appears to be the current -dev version. Let me know if you want me to patch against 8.x-3.x-dev-1704738-tstoeckler and I'll do so.

It's a simple patch that adds a conditional to make sure that the foreach is working against arrays and I've patched two of the functions.

awasson’s picture

Patch against: 8.x-3.x

tstoeckler’s picture

Category: bug » support
Status: Active » Fixed

Thanks for playing with the 8.x version, that's very much appreciated! In this particular case, though, I think the problem is not with Libraries API. As is documented in hook_libraries_info() the 'js' and 'css' keys should have arrays as values. In your case it should be something like:

...
        'js' => array('/js/myjs.js'),
        'css' => array('/css/mycss.css'),

Also, to add a library to a render array, you should do:

$page['#attached']['libraries_load'] = array('mylibrary');

This isn't documented anywhere, but it should work fine. If you know somewhere, where this could be documented, that would be great!

awasson’s picture

Wow! That just reduced my page build code to 1 line.

I though that it might be that each file in my files array needed to be defined as arrays too but I couldn't see how to access them when I did that. Now I do. Holy smokes, that is powerful!

I think I'll add a page to the documentation outlining how to tinker with the version 8 leg. Awesome module by the way!

Cheers,
Andrew

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Added info about Drupal/Libraries API versions and environment