I'm trying to make a custom module based on menu module to render a sitemap.
I want to use a custom theme function for rendering it but for unknown reasons my variables are not passed to the theme function. Here is my code (simplified so we get what matter) :
function custom_module_theme() {
return array(
'custom_module_link' => array(
'variables' => array(
'attributes' => NULL,
'title' => NULL,
'href' => NULL,
'below' => NULL,
'original_link' => NULL,
),
),
);
}
function theme_custom_module_link(array $variables) {
$element = $variables;
$output = ...;
...
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . "</li>\n";
}
function _custom_module_tree_output($tree) {
...
...
// Allow menu-specific theme overrides.
$element['#theme'] = 'custom_module_link';
$element['#attributes']['class'] = $class;
$element['#title'] = $data['link']['link_title'];
$element['#href'] = $data['link']['link_path'];
$element['#original_link'] = $data['link'];
}
return $element;
}
function custom_module_page() {
$tree = ...
$output = _custom_module_tree_output($tree);
return drupal_render($output);
}
This code return a error page with the following : TypeError: Argument 1 passed to drupal_attributes() must be of the type array, null given ...
I don't understand why drupal_render doesn't iterate over the $element['#theme'] call to fetch variables as described in the documentation. What I'm missing ?
From the doc : Basically, the '#theme' = 'function_name' calls theme_function_name(), and other array values of the form '#var_name' = $value in the same array are passed as arguments to the theme function
If I dpm $variables in my theme_custom_module_link function, variables are set as NULL as in my hook_theme ...
template
orrender element
in thehook_theme
definition - one of them is required