1

I am writing a custom module for commerce shipping and want to use the shipping company's web service code in my module. My thinking is to include it as a library using the Libraries module. I use hook_libraries_info() to define the library but when I want to load it later on using the libraries_load() function I get the error message. I'm using colorbox that is dependent on Libraries and that is working fine. I have also made my module dependent on the Libraries module in mymodule.info. What am I doing wrong? Why is my custom module not able to use a function in the Libraries module?

Also, my module is an exact copy of commerce_shipping_example but it includes the hook mentioned above. The code that I've tried:

libraries_load('commerce_shipping_mds', $variant);
libraries_load('commerce_shipping_mds');

and

if (module_exists('libraries')) {
  libraries_load('commerce_shipping_mds', $variant);
}

I've seen this question asked many times and almost all the answers has got something to do with the Libraries version. I have tried all the available versions and still get the same error in apache2/error.log.

All of the code (except for libraries, off course) is in my commerce_shipping_mds.module file. The currently installed Libraries version is 7.x-2.2+5-dev and I see the schema version in the system table for sites/all/modules/libraries/libraries.module is 7200. I also see there is another entry in there sites/all/modules/libraries/tests/modules/libraries_test_module/libraries_test_module.module and the .info says : This is an example info file of a library used for testing purposes. Am I supposed to have an entry like this for my library?

Here is my hook_libraries_info():

function commerce_shipping_mds_libraries_info() {
  $libraries['commerce_shipping_mds'] = array(
    'name' => 'MDS library', 
    'vendor url' => 'http://collivery.co.za', 
    'download url' => 'http://collivery.co.za',
    'files' => array(
      'php' => array(
        'Cache.php',
        'Collivery.php'
      )
    ),
  );
  return $libraries;
}

Thanks for the help.

Forgot to add - I'm trying the libraries_load() function later in the .module file.

Drush libraries-list gives the following output:

Name                   Status        Version  Variants          Dependencies
commerce_shipping_mds  Not detected  -        -                 -
colorbox               OK            1.5.14   minified, source  -
  • 1
    So which version of libraries are you using (also make sure you don't have multiple versions of the libraries module in your file system, in which case it might not be using the one you expect)? Where are you calling the function from? If it still throws that error with your second code example I would also guess wrong module version. You can also check your system table in the database for the schema number of the libraries module and the path to your module, so you can guarantee what version is being used. – rooby Nov 27 '14 at 11:44
  • Please post your hook_libraries_info() – Andy Nov 27 '14 at 12:13
  • The libraries test module is fine, you can ignore that. – rooby Nov 27 '14 at 14:11
  • Are you sure the Libraries module is enabled? Also does the server have necessary permissions to read libraries module files? What does die(module_exists('libraries')); output on the line where it's failing? If nothing then it means it's returning FALSE. – Beebee Nov 27 '14 at 14:33
  • Libraries is definitely enabled as I use it with Colorbox successfully. Permissions are 755 for www-data. die(module_exists('libraries')); returns 1 – Christo Nov 27 '14 at 14:47

Your Answer

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

Browse other questions tagged or ask your own question.