API page: http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_g...

Enter a descriptive title (above) relating to drupal_get_path, then describe the problem you have found:
There is no mention of what happens when the file is not found. A quick test shows the file function returns a binary zero and that makes dirname return an empty string.
drupal_get_path('module', 'sdkjghfsdjklghfsdkjghfds'); returns an empty string.
There may be other possibilities in the code.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

Title: Returns FALSE if the file is not found. » Document that drupal_get_path() returns an empty string if the file is not found
Version: 7.x-dev » 8.x-dev
Issue tags: +Novice, +Needs backport to D7

Thanks -- we should document this in 8.x first and then backport to 7.x.

richard.c.allen2386’s picture

Status: Active » Needs review
FileSize
521 bytes

Here you go, this should be good?

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! Can you clean up the grammar and combine the two possibilities? Something like:
@return
Blah blah blah, or foo if (whatever, but include a verb).

richard.c.allen2386’s picture

re-rolled, wasn't quite clear on the second part nor was anyone else in the office. maybe we're all terrible at grammar!

richard.c.allen2386’s picture

Status: Needs work » Needs review
jhodgdon’s picture

How about "... if the file is not found" for the second part?

mitron’s picture

It is less clear to call a module a "file" than an "item" so perhaps something like "....or an empty string if the item is not found." Perhaps something like the following:

/**
 * Returns the path to a system item (module, theme, etc.).
 *
 * @param $type
 *   The type of the item (i.e. theme, theme_engine, module, profile).
 * @param $name
 *   The name of the item for which the path is requested.
 *
 * @return
 *   The path to the requested item or an empty string if the item is not found.
 */
function drupal_get_path($type, $name) {
  return dirname(drupal_get_filename($type, $name));
}
jhodgdon’s picture

#7 seems fine to me. Just make sure the line wraps if it goes over 80 characters. Thanks!

mitron’s picture

Looks like drupal_get_filename() returns NULL not an empty string when the file does not exist. There should be a test that asserts this.

peterx’s picture

richard.c.allen2386’s picture

I re-rolled using the comment from #7. The test function in #10 seems to indicate that it is an empty string.

jhodgdon’s picture

Assigned: Unassigned » jhodgdon
Status: Needs review » Reviewed & tested by the community

Thanks! I'll get this committed when the test result turns green.

mitron’s picture

Does the backport for V7 go in this issue too?

jhodgdon’s picture

It will, but wait until the 8.x version is committed. Often the same patch can be applied and no one has to do any more work backporting it. :)

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks again -- Committed to both 8.x and 7.x (no port required).

jhodgdon’s picture

Assigned: jhodgdon » Unassigned

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