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