pathValidator = $path_validator; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static($container->get('path.validator')); } /** * Creates a new link in the provided shortcut set. * * @param \Drupal\shortcut\ShortcutSetInterface $shortcut_set * The shortcut set to add a link to. * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * * @return \Symfony\Component\HttpFoundation\RedirectResponse * A redirect response to the front page, or the previous location. * * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */ 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([ 'title' => $name, 'shortcut_set' => $shortcut_set->id(), 'link' => [ 'uri' => 'internal:/' . $link, ], ]); try { $shortcut->save(); drupal_set_message($this->t('Added a shortcut for %title.', ['%title' => $shortcut->label()])); } catch (\Exception $e) { drupal_set_message($this->t('Unable to add a shortcut for %title.', ['%title' => $shortcut->label()]), 'error'); } return $this->redirect(''); } throw new AccessDeniedHttpException(); } }