You are here

public function ShortcutSetController::addShortcutLinkInline in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 59
Contains \Drupal\shortcut\Controller\ShortcutSetController.

Class

ShortcutSetController
Builds the page for administering shortcut sets.

Namespace

Drupal\shortcut\Controller

Code

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
      ->entityManager()
      ->getStorage('shortcut')
      ->create(array(
      'title' => $name,
      'shortcut_set' => $shortcut_set
        ->id(),
      'link' => array(
        'uri' => 'internal:/' . $link,
      ),
    ));
    try {
      $shortcut
        ->save();
      drupal_set_message($this
        ->t('Added a shortcut for %title.', array(
        '%title' => $shortcut
          ->label(),
      )));
    } catch (\Exception $e) {
      drupal_set_message($this
        ->t('Unable to add a shortcut for %title.', array(
        '%title' => $shortcut
          ->label(),
      )), 'error');
    }
    return $this
      ->redirect('<front>');
  }
  throw new AccessDeniedHttpException();
}