function ShortcutSetController::addShortcutLinkInline
Same name in other branches
- 9 core/modules/shortcut/src/Controller/ShortcutSetController.php \Drupal\shortcut\Controller\ShortcutSetController::addShortcutLinkInline()
- 8.9.x core/modules/shortcut/src/Controller/ShortcutSetController.php \Drupal\shortcut\Controller\ShortcutSetController::addShortcutLinkInline()
- 11.x core/modules/shortcut/src/Controller/ShortcutSetController.php \Drupal\shortcut\Controller\ShortcutSetController::addShortcutLinkInline()
Creates a new link in the provided shortcut set.
Parameters
\Drupal\shortcut\ShortcutSetInterface $shortcut_set: The shortcut set to add a link to.
\Symfony\Component\HttpFoundation\Request $request: The request object.
Return value
\Symfony\Component\HttpFoundation\RedirectResponse A redirect response to the front page, or the previous location.
Throws
\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
1 string reference to 'ShortcutSetController::addShortcutLinkInline'
- shortcut.routing.yml in core/
modules/ shortcut/ shortcut.routing.yml - core/modules/shortcut/shortcut.routing.yml
File
-
core/
modules/ shortcut/ src/ Controller/ ShortcutSetController.php, line 46
Class
- ShortcutSetController
- Builds the page for administering shortcut sets.
Namespace
Drupal\shortcut\ControllerCode
public function addShortcutLinkInline(ShortcutSetInterface $shortcut_set, Request $request) {
$link = $request->query
->get('link');
$name = $request->query
->get('name');
if (parse_url($link, PHP_URL_SCHEME) === NULL && $this->pathValidator
->isValid($link)) {
$shortcut = $this->entityTypeManager()
->getStorage('shortcut')
->create([
'title' => $name,
'shortcut_set' => $shortcut_set->id(),
'link' => [
'uri' => 'internal:/' . $link,
],
]);
try {
$shortcut->save();
$this->messenger()
->addStatus($this->t('Added a shortcut for %title.', [
'%title' => $shortcut->label(),
]));
} catch (\Exception $e) {
$this->messenger()
->addError($this->t('Unable to add a shortcut for %title.', [
'%title' => $shortcut->label(),
]));
}
return $this->redirect('<front>');
}
throw new AccessDeniedHttpException();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.