Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / media / src / MediaForm.php
1 <?php
2
3 namespace Drupal\media;
4
5 use Drupal\Core\Entity\ContentEntityForm;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Form controller for the media edit forms.
10  */
11 class MediaForm extends ContentEntityForm {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function form(array $form, FormStateInterface $form_state) {
17     $form = parent::form($form, $form_state);
18     /** @var \Drupal\media\MediaTypeInterface $media_type */
19     $media_type = $this->entity->bundle->entity;
20
21     if ($this->operation === 'edit') {
22       $form['#title'] = $this->t('Edit %type_label @label', [
23         '%type_label' => $media_type->label(),
24         '@label' => $this->entity->label(),
25       ]);
26     }
27
28     // Media author information for administrators.
29     if (isset($form['uid']) || isset($form['created'])) {
30       $form['author'] = [
31         '#type' => 'details',
32         '#title' => $this->t('Authoring information'),
33         '#group' => 'advanced',
34         '#attributes' => [
35           'class' => ['media-form-author'],
36         ],
37         '#weight' => 90,
38         '#optional' => TRUE,
39       ];
40     }
41
42     if (isset($form['uid'])) {
43       $form['uid']['#group'] = 'author';
44     }
45
46     if (isset($form['created'])) {
47       $form['created']['#group'] = 'author';
48     }
49
50     $form['#attached']['library'][] = 'media/form';
51
52     return $form;
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public function save(array $form, FormStateInterface $form_state) {
59     $saved = parent::save($form, $form_state);
60     $context = ['@type' => $this->entity->bundle(), '%label' => $this->entity->label()];
61     $logger = $this->logger('media');
62     $t_args = ['@type' => $this->entity->bundle->entity->label(), '%label' => $this->entity->label()];
63
64     if ($saved === SAVED_NEW) {
65       $logger->notice('@type: added %label.', $context);
66       drupal_set_message($this->t('@type %label has been created.', $t_args));
67     }
68     else {
69       $logger->notice('@type: updated %label.', $context);
70       drupal_set_message($this->t('@type %label has been updated.', $t_args));
71     }
72
73     $form_state->setRedirectUrl($this->entity->toUrl('canonical'));
74     return $saved;
75   }
76
77 }