1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- function ctools_menu_add_tab($link = NULL) {
- $links = &drupal_static(__FUNCTION__, array());
- if (isset($link)) {
- $links[$link['href']] = $link;
- }
- return $links;
- }
- function ctools_menu_sort($a, $b) {
- $a_weight = (is_array($a) && isset($a['#link']['weight'])) ? $a['#link']['weight'] : 0;
- $b_weight = (is_array($b) && isset($b['#link']['weight'])) ? $b['#link']['weight'] : 0;
- if ($a_weight == $b_weight) {
- $a_title = (is_array($a) && isset($a['#link']['title'])) ? $a['#link']['title'] : 0;
- $b_title = (is_array($b) && isset($b['#link']['title'])) ? $b['#link']['title'] : 0;
- if ($a_title == $b_title) {
- return 0;
- }
- return ($a_title < $b_title) ? -1 : 1;
- }
- return ($a_weight < $b_weight) ? -1 : 1;
- }
- function _ctools_menu_add_dynamic_items(&$data, &$router_item, &$root_path) {
- if ($additions = ctools_menu_add_tab()) {
-
-
- $has_active = FALSE;
- if (!empty($data['tabs'][0]['output'])) {
- foreach ($data['tabs'][0]['output'] as $element) {
- if (!empty($element['#link']['#active'])) {
- $has_active = TRUE;
- }
- }
- }
- foreach ($additions as $addition) {
- $addition['localized_options'] = isset($addition['options']) ? $addition['options'] : array();
- if (isset($addition['type']) && $addition['type'] == MENU_LOCAL_ACTION) {
- $data['actions']['output'][] = array(
- '#theme' => 'menu_local_action',
- '#link' => $addition,
- );
- }
- else {
- $data['tabs'][0]['output'][] = array(
- '#theme' => 'menu_local_task',
- '#link' => $addition,
- '#active' => (!$has_active && $root_path === $addition['href']),
- );
- }
- }
- if (!empty($data['tabs'][0]['output'])) {
- uasort($data['tabs'][0]['output'], 'ctools_menu_sort');
- $data['tabs'][0]['count'] = count($data['tabs'][0]['output']);
- }
- if (!empty($data['actions']['output'])) {
- uasort($data['actions']['output'], 'ctools_menu_sort');
- $data['actions']['count'] = count($data['actions']['output']);
- }
- }
- }
|