When extending the base Walker class I need to extend the walk()
method.
However, calling the parent walk()
method yields no results.
These are the approaches I have tried:
public function walk($elements, $max_depth) {
parent::walk($elements, $max_depth);
}
public function walk($elements, $max_depth) {
$parent_class=get_parent_class($this);
$args = array($elements, $max_depth);
call_user_func_array(array($parent_class, 'walk'), $args);
}
It appears to me that as soon as I override the walk()
things break.
Should this method return some specific value? Should I call the parent method differently?
Walker::walk
will return the string resulting from the walk operation.
What you will get is a text that has been created using the methods Walker::display_element
, Walker::start_lvl
, Walker::start_el
and so on...
What you will get from the parent method is already HTML code probably hard to modify in the right way in a second time, but if you really want to do that:
public function walk($elements, $max_depth) {
$html = parent::walk($elements, $max_depth);
/* Do something with the HTML output */
return $html;
}