You are here

function patterns_parser_build_formats_index in Patterns 7.2

Same name and namespace in other branches
  1. 7 includes/parser/parser.inc \patterns_parser_build_formats_index()

Register all available patterns parsers and returns an associative array.

Invokes all the modules implementing <hook_patterns_parser>.

Modules implenting such hook are expected to return an associative array of the type:

$parser = array(); $parser['format'] = 'php; $parser['parser'] = 'patterns_phpparser'; $parser['overwrite'] = TRUE; // (Optional) Default is TRUE

Patterns will then call

  • <patterns_phpparser_parse()>
  • <patterns_phpparser_dump()>
  • <patterns_phpparser_load()>

for performing parsing operations with the PHP format.

Parameters

bool $reset (optional) If TRUE, forces to rebuild the index.:

Return value

array $patterns_formats The associative array of available parsers.

5 calls to patterns_parser_build_formats_index()
patterns_first_install in includes/forms/first_install.inc
patterns_info_parsers in includes/forms/info.inc
Displays a summary of Patterns parsers
patterns_parser_exists in includes/parser/parser.inc
Checks wheter a parser is defined for a given format.
patterns_parser_get_formats in includes/parser/parser.inc
Returns an array of formats currently supported by the patterns module.
patterns_parser_get_parser_function in includes/parser/parser.inc
Checks whether a parser is defined for a given format, and returns the corresponding function name for the requested action.

File

includes/parser/parser.inc, line 38

Code

function patterns_parser_build_formats_index($reset = TRUE) {
  static $patterns_formats;
  if (!$reset) {
    return $patterns_formats;
  }
  if (!is_array($patterns_formats)) {
    $patterns_formats = array();
  }
  $modules = module_implements('patterns_parser');
  foreach ($modules as $module) {
    $parser = module_invoke($module, 'patterns_parser');
    if (!is_array($parser) || !isset($parser['parser']) || !isset($parser['format'])) {
      continue;
    }
    $format = $parser['format'];
    $parser = $parser['parser'];
    $ow = isset($parser['overwrite']) ? isset($parser['overwrite']) : TRUE;

    // overwrite by default
    // If the parser already exists and we are not
    // allowed to overwrite it, contintue
    if (!$ow && patterns_parser_exists($format, FALSE)) {
      continue;
    }
    $patterns_formats[$format] = $parser;
  }
  return $patterns_formats;
}