function shortcut_admin_add_link

shortcut_admin_add_link($shortcut_link, &$shortcut_set, $limit = NULL)

Adds a link to the end of a shortcut set, keeping within a prescribed limit.

Parameters

$link: An array representing a shortcut link.

$shortcut_set: An object representing the shortcut set which the link will be added to. The links in the shortcut set will be re-weighted so that the new link is at the end, and some existing links may be disabled (if the $limit parameter is provided).

$limit: (optional) The maximum number of links that are allowed to be enabled for this shortcut set. If provided, existing links at the end of the list that exceed the limit will be automatically disabled. If not provided, no limit will be enforced.

File

modules/shortcut/shortcut.admin.inc, line 566
Administrative page callbacks for the shortcut module.

Code

function shortcut_admin_add_link($shortcut_link, &$shortcut_set, $limit = NULL) {
  if (isset($limit)) {
    // Disable any existing links at the end of the list that would cause the
    // limit to be exceeded. Take into account whether or not the new link will
    // be enabled and count towards the total.
    $number_enabled = !empty($shortcut_link['hidden']) ? 0 : 1;
    foreach ($shortcut_set->links as &$link) {
      if (!$link['hidden']) {
        $number_enabled++;
        if ($number_enabled > $limit) {
          $link['hidden'] = 1;
        }
      }
    }
  }

  // Normalize the path in case it is an alias.
  $shortcut_link['link_path'] = drupal_get_normal_path($shortcut_link['link_path']);
  if (empty($shortcut_link['link_path'])) {
    $shortcut_link['link_path'] = '<front>';
  }

  // Add the link to the end of the list.
  $shortcut_set->links[] = $shortcut_link;
  shortcut_set_reset_link_weights($shortcut_set);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!shortcut!shortcut.admin.inc/function/shortcut_admin_add_link/7.x