3 namespace Drupal\shortcut;
5 use Drupal\Core\Entity\ContentEntityForm;
6 use Drupal\Core\Form\FormStateInterface;
9 * Form handler for the shortcut entity forms.
13 class ShortcutForm extends ContentEntityForm {
16 * The entity being used by this form.
18 * @var \Drupal\shortcut\ShortcutInterface
25 public function save(array $form, FormStateInterface $form_state) {
26 $entity = $this->entity;
27 $status = $entity->save();
28 $url = $entity->getUrl();
29 // There's an edge case where a user can have permission to
30 // 'link to any content', but has no right to access the linked page. So we
31 // check the access before showing the link.
33 $view_link = \Drupal::l($entity->getTitle(), $url);
36 $view_link = $entity->getTitle();
39 if ($status == SAVED_UPDATED) {
40 $message = $this->t('The shortcut %link has been updated.', ['%link' => $view_link]);
43 $message = $this->t('Added a shortcut for %title.', ['%title' => $view_link]);
45 $this->messenger()->addStatus($message);
47 $form_state->setRedirect(
48 'entity.shortcut_set.customize_form',
49 ['shortcut_set' => $entity->bundle()]