You are here

function finder::element_weights in Finder 7.2

Order elements by weight.

File

includes/finder.inc, line 154
finder.inc

Class

finder
An object to contain all of the data to generate a finder, plus the member functions to build the finder, and render the output.

Code

function element_weights() {
  if (!empty($this->elements)) {

    // First do a quick and dirty sort, at least elements that are siblings
    // with each other will be in the right order.
    uasort($this->elements, array(
      $this,
      '_element_weights_sort',
    ));

    // Now we need to ensure parents come before children.
    $elements = array();
    $root_elements = $this
      ->root_elements();
    foreach ($root_elements as $root) {
      $this
        ->_element_weights($root, $elements);
    }
    $finder_elements = array();
    foreach ($elements as $weight => $element_id) {
      $finder_element = $this->elements[$element_id];
      $finder_element->weight = $weight;
      $finder_elements[$element_id] = $finder_element;
    }
    $this->elements = $finder_elements;
  }
}