You are here

function libraries_admin_path_to_tree in Libraries API 7.2

Converts a file path into a tree structure for use in an item list.

For example, the path 'foo/bar/baz' will be converted into the tree structure represented by the following list:

  • foo

    • bar

      • baz

The $items array that is modified by reference or returned (see below) can be used as the 'items' variable for theme_item_list().

This function modifies passed-in $items array, so that multiple paths can be placed into the same tree structure easily.

$items = array();
foreach ($paths as $path) {
  libraries_admin_path_to_tree($items, $path);
}

It also returns the last item by reference, so that it can also be used to traverse into a sub-structure and add further children there.

$items = array();
$children =& libraries_admin_path_to_tree($items, $path);
foreach ($sub_paths as $sub_path) {
  libraries_admin_path_to_tree($children, $sub_path);
}

Parameters

array $items:

string $path:

Return value

array

1 call to libraries_admin_path_to_tree()
libraries_admin_directory_layout in ./libraries.admin.inc
Returns the directory layout of the library, if possible.

File

./libraries.admin.inc, line 519
Provides administrative page and form callbacks for Libraries module.

Code

function &libraries_admin_path_to_tree(array &$items, $path) {
  $part = strtok($path, '/');
  while ($part) {
    if (!isset($items[$part])) {
      $items[$part] = array(
        'data' => $part,
        'children' => array(),
      );
    }
    $items =& $items[$part]['children'];
    $part = strtok('/');
  }
  return $items;
}