function _potx_find_menu_hooks in Translation template extractor 7
Same name and namespace in other branches
- 8 potx.inc \_potx_find_menu_hooks()
- 6.3 potx.inc \_potx_find_menu_hooks()
- 7.3 potx.inc \_potx_find_menu_hooks()
- 7.2 potx.inc \_potx_find_menu_hooks()
List of menu item titles. Only from Drupal 6.
Parameters
$file: Full path name of file parsed.
$filebase: Filenaname of file parsed.
$save_callback: Callback function used to save strings.
1 call to _potx_find_menu_hooks()
- _potx_process_file in ./
potx.inc - Process a file and put extracted information to the given parameters.
File
- ./
potx.inc, line 1089 - Extraction API used by the web and command line interface.
Code
function _potx_find_menu_hooks($file, $filebase, $save_callback) {
global $_potx_tokens, $_potx_lookup;
$hooks = array(
'_menu',
'_menu_alter',
);
$keys = array(
"'title'",
'"title"',
"'description'",
'"description"',
);
foreach ($hooks as $hook) {
if (isset($_potx_lookup[$filebase . $hook]) && is_array($_potx_lookup[$filebase . $hook])) {
// We have this menu hook in this file.
foreach ($_potx_lookup[$filebase . $hook] as $ti) {
$end = _potx_find_end_of_function($ti);
$tn = $ti;
while ($tn < $end) {
// Support for array syntax more commonly used in menu hooks:
// $items = array('node/add' => array('title' => 'Add content'));
if ($_potx_tokens[$tn][0] == T_CONSTANT_ENCAPSED_STRING && in_array($_potx_tokens[$tn][1], $keys) && $_potx_tokens[$tn + 1][0] == T_DOUBLE_ARROW) {
if ($_potx_tokens[$tn + 2][0] == T_CONSTANT_ENCAPSED_STRING) {
// We cannot export menu item context.
$save_callback(_potx_format_quoted_string($_potx_tokens[$tn + 2][1]), POTX_CONTEXT_NONE, $file, $_potx_tokens[$tn + 2][2]);
$tn += 2;
// Jump forward by 2.
}
else {
potx_status('error', t('Invalid menu %element definition found in %hook. Title and description keys of the menu array should be literal strings.', array(
'%element' => $_potx_tokens[$tn][1],
'%hook' => $filebase . $hook . '()',
)), $file, $_potx_tokens[$tn][2], NULL, 'http://drupal.org/node/323101');
}
}
// Support for array syntax more commonly used in menu alters:
// $items['node/add']['title'] = 'Add content here';
if (is_string($_potx_tokens[$tn]) && $_potx_tokens[$tn] == '[' && $_potx_tokens[$tn + 1][0] == T_CONSTANT_ENCAPSED_STRING && in_array($_potx_tokens[$tn + 1][1], $keys) && is_string($_potx_tokens[$tn + 2]) && $_potx_tokens[$tn + 2] == ']') {
if (is_string($_potx_tokens[$tn + 3]) && $_potx_tokens[$tn + 3] == '=' && $_potx_tokens[$tn + 4][0] == T_CONSTANT_ENCAPSED_STRING) {
// We cannot export menu item context.
$save_callback(_potx_format_quoted_string($_potx_tokens[$tn + 4][1]), POTX_CONTEXT_NONE, $file, $_potx_tokens[$tn + 4][2]);
$tn += 4;
// Jump forward by 4.
}
else {
potx_status('error', t('Invalid menu %element definition found in %hook. Title and description keys of the menu array should be literal strings.', array(
'%element' => $_potx_tokens[$tn + 1][1],
'%hook' => $filebase . $hook . '()',
)), $file, $_potx_tokens[$tn + 1][2], NULL, 'http://drupal.org/node/323101');
}
}
$tn++;
}
}
}
}
}