i am busy prepping a module for release by making it drupal friendly and one of the things i have needed to do is remove an external library from the module itself and i have used the libraries api to do this for me

previously the one external lib file lived in the same directory as the module and was referenced with the following code:

require_once('simple_html_dom.php');

since moving the file to sites/all/libraries/simplehtmldom/simple_html_dom.php

the assumed way of getting it working with libraries api is:

require_once(libraries_get_path($library_name);.'simple_html_dom.php');

however this doesnt work with an include error:

warning: require_once(sites/all/libraries/simple_html_dom.php) [function.require-once]: failed to open stream: No such file or directory in /Users/anthonysomerset/Sites/drupal-6.16/sites/all/modules/google_form/google_form.module on line 160.

notice it missing the directory off

to get the code to work i actually have to do the following:
require_once(libraries_get_path($library_name);.'simplehtmldom/simple_html_dom.php');

is this correct or is this a bug or am i just doing something wrong

Comments

Grayside’s picture

Is that semicolon in the middle a typo from your post here? It does not belong.

anthonysomerset’s picture

yes a typo, my live code doesnt have it
but it called my code checking up and i solved the issue with

require_once(libraries_get_path(simplehtmldom).'/simple_html_dom.php');

dropped the dollar sign :)

my issue is fixed but perhaps the documentation can be improved?

sun’s picture

Category: bug » support

1) Even if the library does not exist, Libraries API returns the path 'sites/all/libraries/$directory'.

2) You need to call file_exists() on the returned path + ideally an expected library file within that directory yourself.

3) You should use include_once() instead of require_once(), since a missing library shouldn't really break your entire site.

4) Current efforts in #719896: Add a hook_libraries_info() will simplify this integration logic for all modules.

tstoeckler’s picture

Status: Active » Fixed

Marking fixed in order to clean-up the issue queue.
Please re-open if any problems or questions persist.

Status: Fixed » Closed (fixed)

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