You are here

function ds_element_children in Display Suite 6.3

Same name and namespace in other branches
  1. 6.2 ds.module \ds_element_children()

Return elements of an array which are children (i.e. not starting with #)

This is a direct port of element_children from Drupal 7

Parameters

$elements: The element array whose children are to be identified.

$sort: Boolean to indicate whether the children should be sorted by weight.

Return value

The array keys of the element's children.

1 call to ds_element_children()
dsDisplay::regionsAddContent in includes/dsDisplay.php
For all regions, add content from provided fields

File

./ds.module, line 807

Code

function ds_element_children(&$elements, $sort = FALSE) {

  // Do not attempt to sort elements which have already been sorted.
  $sort = isset($elements['#sorted']) ? !$elements['#sorted'] : $sort;

  // Filter out properties from the element, leaving only children.
  $children = array();
  $sortable = FALSE;
  foreach ($elements as $key => $value) {
    if ($key === '' || $key[0] !== '#') {
      $children[$key] = $value;
      if (is_array($value) && isset($value['#weight'])) {
        $sortable = TRUE;
      }
    }
  }

  // Sort the children if necessary.
  if ($sort && $sortable) {
    uasort($children, 'element_sort');

    // Put the sorted children back into $elements in the correct order, to
    // preserve sorting if the same element is passed through
    // element_children() twice.
    foreach ($children as $key => $child) {
      unset($elements[$key]);
      $elements[$key] = $child;
    }
    $elements['#sorted'] = TRUE;
  }
  return array_keys($children);
}