API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21SystemLis...

The example code used in that page is introduced by the following phrase:

For instance, if you are looking for modules and call

Then the description continues with the following text:

this function will search:

  • the core modules directory; i.e., /core/modules
  • the profiles directories as defined by the profiles() method.
  • the site-wide modules directory; i.e., /modules
  • the all-sites directory; i.e., /sites/all/modules
  • the site-specific directory; i.e., /sites/example.com/modules

That is not what the code is doing, since the code is the following one.

$scanner = new SystemListing();
$all_profiles = $profiles_scanner->scan('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.profile$/', 'profiles');

Since the description for the $string parameter is the following one, the shown code should show how to search for modules, not profiles.

The subdirectory name in which the files are found. For example, 'modules' will search all 'modules' directories and their sub-directories as explained above.

Comments

avpaderno’s picture

Status: Active » Needs review
StatusFileSize
new706 bytes

This is a first patch attempt.

jhodgdon’s picture

Status: Needs review » Needs work

Good catch! But the example code is still wrong. The first line is saved as $scanner, and then the second one uses a different variable.

avpaderno’s picture

StatusFileSize
new696 bytes

Whoops... I missed the thing that was screaming out loud. :|

Let's try again after checking the patch doesn't include any other patch. Let's also use a more appropriate variable name than $all_profiles, since the code is listing all the existing modules.

  $scanner = new SystemListing();
  $all_modules = $scanner->scan('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.module$/', 'modules');
avpaderno’s picture

Status: Needs work » Needs review
jhodgdon’s picture

Title: The example code is wrong » SimpleListing::scan example code is wrong
Status: Needs review » Reviewed & tested by the community

Looks good, thanks!

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks again! Committed to 8.x.

I checked and this is completely new documentation for 8.x. The 7.x equivalent was buried in the body of drupal_system_listing() and that function's documentation is not suffering from the same problem. So, no backport needed.

Status: Fixed » Closed (fixed)

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