You are here

function module_builder_get_hook_data in Module Builder 5

Same name and namespace in other branches
  1. 6.2 includes/process.inc \module_builder_get_hook_data()
  2. 7 includes/process.inc \module_builder_get_hook_data()

Retrieves hook data from downloaded files.

@ param string $type Specify whether to return name, description, or whatever the third one is.

Return value

Array of hook info

2 calls to module_builder_get_hook_data()
generate_module in ./module_builder.module
module_builder_page_input in ./module_builder.module
Module form: 'input' step. Collect module data.

File

./module_builder.module, line 979
Builds scaffolding for custom modules.

Code

function module_builder_get_hook_data($type = MODULE_BUILDER_HOOK_NAMES) {

  // Find path of hook documentation directory
  $path = file_create_path(variable_get('module_builder_hooks_directory', 'hooks')) . '/';

  // Get list of hook documentation files
  $files = module_builder_get_doc_files($path);
  if (!isset($files)) {
    return NULL;
  }

  // Build list of hooks
  $hook_groups = array();
  foreach ($files as $file) {
    $hook_data = module_builder_extract_hook_data($path, $file, $type);
    if ($type == MODULE_BUILDER_HOOK_NAMES) {

      // Obtain list of descriptions
      $descriptions = module_builder_extract_hook_data($path, $file, MODULE_BUILDER_HOOK_DESCRIPTIONS);
      $file_name = substr($file, 0, strrpos($file, '.'));

      // Create an array in the form of:
      // array(
      //   'filename' => array(
      //     array('hook' => 'hook_foo', 'description' => 'hook_foo description'),
      //     ...
      //   ),
      //   ...
      // );
      foreach ($hook_data as $key => $hook) {

        // Remove extra "* " for multi-line descriptions
        $description = str_replace('* ', '', $descriptions[$key]);
        $hook_groups[$file_name][$key] = array(
          'name' => $hook,
          'description' => $description,
        );
      }
    }
    elseif ($type == MODULE_BUILDER_HOOK_DECLARATIONS) {
      $hook_names = module_builder_extract_hook_data($path, $file, MODULE_BUILDER_HOOK_NAMES);

      // Create an array in the form of:
      // array(
      //   'hook_foo' => 'function hook_foo( ... ) {',
      //     ...
      // );
      foreach ($hook_data as $key => $declaration) {
        $hook_groups[$hook_names[$key]] = $declaration;
      }
    }
  }
  return $hook_groups;
}