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 form(array $form, FormStateInterface $form_state) {
26 $form = parent::form($form, $form_state);
27 $form['#attached']['library'][] = 'core/drupal.form';
35 public function save(array $form, FormStateInterface $form_state) {
36 $entity = $this->entity;
37 $status = $entity->save();
38 $url = $entity->getUrl();
39 // There's an edge case where a user can have permission to
40 // 'link to any content', but has no right to access the linked page. So we
41 // check the access before showing the link.
43 $view_link = \Drupal::l($entity->getTitle(), $url);
46 $view_link = $entity->getTitle();
49 if ($status == SAVED_UPDATED) {
50 $message = $this->t('The shortcut %link has been updated.', ['%link' => $view_link]);
53 $message = $this->t('Added a shortcut for %title.', ['%title' => $view_link]);
55 $this->messenger()->addStatus($message);
57 $form_state->setRedirect(
58 'entity.shortcut_set.customize_form',
59 ['shortcut_set' => $entity->bundle()]