Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / shortcut / src / ShortcutForm.php
1 <?php
2
3 namespace Drupal\shortcut;
4
5 use Drupal\Core\Entity\ContentEntityForm;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Form handler for the shortcut entity forms.
10  *
11  * @internal
12  */
13 class ShortcutForm extends ContentEntityForm {
14
15   /**
16    * The entity being used by this form.
17    *
18    * @var \Drupal\shortcut\ShortcutInterface
19    */
20   protected $entity;
21
22   /**
23    * {@inheritdoc}
24    */
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.
32     if ($url->access()) {
33       $view_link = \Drupal::l($entity->getTitle(), $url);
34     }
35     else {
36       $view_link = $entity->getTitle();
37     }
38
39     if ($status == SAVED_UPDATED) {
40       $message = $this->t('The shortcut %link has been updated.', ['%link' => $view_link]);
41     }
42     else {
43       $message = $this->t('Added a shortcut for %title.', ['%title' => $view_link]);
44     }
45     $this->messenger()->addStatus($message);
46
47     $form_state->setRedirect(
48       'entity.shortcut_set.customize_form',
49       ['shortcut_set' => $entity->bundle()]
50     );
51   }
52
53 }