Adds a link to the end of a shortcut set, keeping within a prescribed limit.
$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).
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);
}