Security update for Core, with self-updated composer
[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 class ShortcutForm extends ContentEntityForm {
12
13   /**
14    * The entity being used by this form.
15    *
16    * @var \Drupal\shortcut\ShortcutInterface
17    */
18   protected $entity;
19
20   /**
21    * {@inheritdoc}
22    */
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.
30     if ($url->access()) {
31       $view_link = \Drupal::l($entity->getTitle(), $url);
32     }
33     else {
34       $view_link = $entity->getTitle();
35     }
36
37     if ($status == SAVED_UPDATED) {
38       $message = $this->t('The shortcut %link has been updated.', ['%link' => $view_link]);
39     }
40     else {
41       $message = $this->t('Added a shortcut for %title.', ['%title' => $view_link]);
42     }
43     drupal_set_message($message);
44
45     $form_state->setRedirect(
46       'entity.shortcut_set.customize_form',
47       ['shortcut_set' => $entity->bundle()]
48     );
49   }
50
51 }