function token_element_children in Token 8
2 calls to token_element_children()
- token_render_array in ./token.module
- Do not use this function yet. Its API has not been finalized.
- token_tokens in ./token.tokens.inc
- Implements hook_tokens().
File
- ./token.module, line 581
- Enhances the token API in core: adds a browseable UI, missing tokens, etc.
Code
function token_element_children(&$elements, $sort = FALSE) {
$sort = isset($elements['#sorted']) ? !$elements['#sorted'] : $sort;
$children = [];
$sortable = FALSE;
foreach ($elements as $key => $value) {
if (is_int($key) || $key === '' || $key[0] !== '#') {
$children[$key] = $value;
if (is_array($value) && isset($value['#weight'])) {
$sortable = TRUE;
}
}
}
if ($sort && $sortable) {
uasort($children, 'Drupal\\Component\\Utility\\SortArray::sortByWeightProperty');
foreach ($children as $key => $child) {
unset($elements[$key]);
$elements[$key] = $child;
}
$elements['#sorted'] = TRUE;
}
return array_keys($children);
}