3 namespace Drupal\media;
5 use Drupal\Core\Entity\ContentEntityForm;
6 use Drupal\Core\Form\FormStateInterface;
9 * Form controller for the media edit forms.
11 class MediaForm extends ContentEntityForm {
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;
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(),
28 // Media author information for administrators.
29 if (isset($form['uid']) || isset($form['created'])) {
32 '#title' => $this->t('Authoring information'),
33 '#group' => 'advanced',
35 'class' => ['media-form-author'],
42 if (isset($form['uid'])) {
43 $form['uid']['#group'] = 'author';
46 if (isset($form['created'])) {
47 $form['created']['#group'] = 'author';
50 $form['#attached']['library'][] = 'media/form';
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()];
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));
69 $logger->notice('@type: updated %label.', $context);
70 drupal_set_message($this->t('@type %label has been updated.', $t_args));
73 $form_state->setRedirectUrl($this->entity->toUrl('canonical'));