4

I'm trying to include a PHP library called Geocod.io in my custom module. I am also trying to use the Libraries API. So far I have:

  • Downloaded geocod.io to sites/all/libraries
  • composer install'ed in sites/all/libraries/geocodio
  • Started creating a hook_libraries_info() function with the following contents:

    return array(
      'geocodio' => array(
        'name' => 'Geocod.io',
        'vendor url' => 'http://geocod.io',
        'download url' => 'https://github.com/davidstanley01/geocodio-php',
        'version arguments' => array(),
        'files' => array(
          'php' => array('geocodio/vendor/autoload.php'),
        ),
      ),
    );
    

I have no idea what to put for 'files', is the path the the autoloader the right thing to do? Are these two ways of including things even compatible? I'm a bit stumped as to what to do next, I want to use the geocod.io library and I want to do it the most correct way. Other questions that mention these issues don't seem to include anything about how to list the files/versions.

0

This is not really a direct answer to your question, but as an alternative to using the Libraries API (which I too have struggled with in this context), check out the Composer Manager module. It works nicely for PHP libraries installed via Composer, and takes care of the autoload seamlessly.

3
  • It automatically includes the autoload file created by Composer; plus, it load all the libraries in a central directory and verify there aren't conflicts between the libraries required from the modules. Unfortunately, it uses Drush to do part of its task.
    – apaderno
    Oct 29 '15 at 6:40
  • Drush is not a hard requirement (it makes things easier though). You can force a new packages.json from the UI and then run composer install in the sites/default/files/composer folder. But you still need ssh access and permissions to install composer. Oct 29 '15 at 7:39
  • 1
    Whether you use Drush or composer, you can do the library building locally and then upload the results to your webserver. Once the autoload is set up, you don't need the command line tools to use it.
    – Giles B
    Oct 29 '15 at 19:19

Your Answer

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

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