function shortcut_admin_add_link

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 Drupal\shortcut\Plugin\Core\Entity\Shortcut: 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).

2 calls to shortcut_admin_add_link()
shortcut_link_add_inline in drupal/core/modules/shortcut/shortcut.admin.inc
Menu page callback: creates a new link in the provided shortcut set.
shortcut_link_add_submit in drupal/core/modules/shortcut/shortcut.admin.inc
Submit handler for shortcut_link_add().

File

drupal/core/modules/shortcut/shortcut.admin.inc, line 464
Administrative page callbacks for the shortcut module.

Code

function shortcut_admin_add_link($shortcut_link, &$shortcut_set) {

  // Normalize the path in case it is an alias.
  $shortcut_link['link_path'] = drupal_container()
    ->get('path.alias_manager')
    ->getSystemPath($shortcut_link['link_path']);
  if (empty($shortcut_link['link_path'])) {
    $shortcut_link['link_path'] = '<front>';
  }
  $menu_link = entity_create('menu_link', $shortcut_link);
  $menu_link
    ->save();

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