Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/media/src/MediaForm.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
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 * @internal | |
12 */ | |
13 class MediaForm extends ContentEntityForm { | |
14 | |
15 /** | |
16 * {@inheritdoc} | |
17 */ | |
18 public function form(array $form, FormStateInterface $form_state) { | |
19 $form = parent::form($form, $form_state); | |
20 /** @var \Drupal\media\MediaTypeInterface $media_type */ | |
21 $media_type = $this->entity->bundle->entity; | |
22 | |
23 if ($this->operation === 'edit') { | |
24 $form['#title'] = $this->t('Edit %type_label @label', [ | |
25 '%type_label' => $media_type->label(), | |
26 '@label' => $this->entity->label(), | |
27 ]); | |
28 } | |
29 | |
30 // Media author information for administrators. | |
31 if (isset($form['uid']) || isset($form['created'])) { | |
32 $form['author'] = [ | |
33 '#type' => 'details', | |
34 '#title' => $this->t('Authoring information'), | |
35 '#group' => 'advanced', | |
36 '#attributes' => [ | |
37 'class' => ['media-form-author'], | |
38 ], | |
39 '#weight' => 90, | |
40 '#optional' => TRUE, | |
41 ]; | |
42 } | |
43 | |
44 if (isset($form['uid'])) { | |
45 $form['uid']['#group'] = 'author'; | |
46 } | |
47 | |
48 if (isset($form['created'])) { | |
49 $form['created']['#group'] = 'author'; | |
50 } | |
51 | |
52 $form['#attached']['library'][] = 'media/form'; | |
53 | |
54 return $form; | |
55 } | |
56 | |
57 /** | |
58 * {@inheritdoc} | |
59 */ | |
60 public function save(array $form, FormStateInterface $form_state) { | |
61 $saved = parent::save($form, $form_state); | |
62 $context = ['@type' => $this->entity->bundle(), '%label' => $this->entity->label()]; | |
63 $logger = $this->logger('media'); | |
64 $t_args = ['@type' => $this->entity->bundle->entity->label(), '%label' => $this->entity->label()]; | |
65 | |
66 if ($saved === SAVED_NEW) { | |
67 $logger->notice('@type: added %label.', $context); | |
68 drupal_set_message($this->t('@type %label has been created.', $t_args)); | |
69 } | |
70 else { | |
71 $logger->notice('@type: updated %label.', $context); | |
72 drupal_set_message($this->t('@type %label has been updated.', $t_args)); | |
73 } | |
74 | |
75 $form_state->setRedirectUrl($this->entity->toUrl('canonical')); | |
76 return $saved; | |
77 } | |
78 | |
79 } |