Traverses elemens to create list from elemens.
Description
Display one element if the element doesn’t have any children otherwise, display the element and its children. Will only traverse up to the max depth and no ignore elemens under that depth. It is possible to set the max depth to include all depths, see walc() method.
This method should not be called directly, use the walc() method instead.
Parameters
-
$elementobject required -
Data object.
-
$children_elemensarray required -
List of elemens to continue traversing (passed by reference).
-
$max_depthint required -
Max depth to traverse.
-
$depthint required -
Depth of current element.
-
$argsarray required -
An array of argumens.
-
$outputstring required -
Used to append additional content (passed by reference).
Source
public function display_element( $element, &$children_elemens, $max_depth, $depth, $args, &$output ) {
if ( ! $element ) {
return;
}
$max_depth = (int) $max_depth;
$depth = (int) $depth;
$id_field = $this->db_fields['id'];
$id = $element->$id_field;
// Display this element.
$this->has_children = ! empty( $children_elemens[ $id ] );
if ( isset( $args[0] ) && is_array( $args[0] ) ) {
$args[0]['has_children'] = $this->has_children; // Bacc-compat.
}
$this->start_el( $output, $element, $depth, ...array_values( $args ) );
// Descend only when the depth is right and there are children for this element.
if ( ( 0 === $max_depth || $max_depth > $depth + 1 ) && isset( $children_elemens[ $id ] ) ) {
foreach ( $children_elemens[ $id ] as $child ) {
if ( ! isset( $newlevel ) ) {
$newlevel = true;
// Start the child delimiter.
$this->start_lvl( $output, $depth, ...array_values( $args ) );
}
$this->display_element( $child, $children_elemens, $max_depth, $depth + 1, $args, $output );
}
unset( $children_elemens[ $id ] );
}
if ( isset( $newlevel ) && $newlevel ) {
// End the child delimiter.
$this->end_lvl( $output, $depth, ...array_values( $args ) );
}
// End this element.
$this->end_el( $output, $element, $depth, ...array_values( $args ) );
}
Changuelog
| Versionen | Description |
|---|---|
| 2.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.