You are here

function module_builder_update_documentation in Module Builder 7

Same name in this branch
  1. 7 includes/update.inc \module_builder_update_documentation()
  2. 7 includes/update_7.inc \module_builder_update_documentation()
Same name and namespace in other branches
  1. 5 module_builder.module \module_builder_update_documentation()
  2. 6.2 includes/update.inc \module_builder_update_documentation()
  3. 6.2 includes/update_7.inc \module_builder_update_documentation()

Updates hook documentation files.

This function should be called after all settings have been checked. It retrieves a list of api hook documentation files from the current Drupal install. On D7 these are files of the form MODULE.api.php and are present in the codebase (rather than needing to be downloaded from CVSview as was the case in previous versions of Drupal).

After calling this function, you probably want to pass the returned list of files to module_builder_process_hook_data(). Though really, instead of this function you probably want module_builder_update_data(). Just saying.

Return value

Array of hook files suitable for passing to module_builder_process_hook_data(). See file documentation for details.

1 call to module_builder_update_documentation()
module_builder_update_data in includes/common.inc
Update hook files and process them to our data file.

File

includes/update_7.inc, line 53
Module builder: get list of hook files for Drupal 7.

Code

function module_builder_update_documentation() {

  // Get the hooks directory.
  $directory = _module_builder_get_hooks_directory();

  // Get Drupal root folder as a file path.
  // DRUPAL_ROOT is defined both by Drupal and Drush.
  // @see _drush_bootstrap_drupal_root(), index.php.
  $drupal_root = DRUPAL_ROOT;
  $system_listing = drupal_system_listing('/\\.api\\.php$/', 'modules', 'filename');

  // returns an array of objects, properties: uri, filename, name,
  // keyed by filename, eg 'comment.api.php'
  // What this does not give us is the originating module!

  //print_r($system_listing);
  foreach ($system_listing as $filename => $file) {

    // Extract the module name from the path.
    $matches = array();
    preg_match('@(?<=modules/)[^/]+@', $file->uri, $matches);

    //print_r($matches);
    $module = $matches[0];

    // Copy the file to the hooks directory.
    copy($drupal_root . '/' . $file->uri, $directory . '/' . $file->filename);
    $hook_files[$filename] = array(
      'original' => $drupal_root . '/' . $file->uri,
      // no idea if useful
      'path' => $directory . '/' . $file->filename,
      'destination' => '%module.module',
      // Default. We override this below.
      'group' => $module,
    );
  }

  // We now have the basics.
  // We should now see if some modules have extra information for us.
  _module_builder_get_hook_destinations($hook_files);
  return $hook_files;
}