X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmedia%2Fsrc%2FMediaForm.php;fp=web%2Fcore%2Fmodules%2Fmedia%2Fsrc%2FMediaForm.php;h=33c0d32c6f3045d29a098ef29394929b935cc35d;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/media/src/MediaForm.php b/web/core/modules/media/src/MediaForm.php new file mode 100644 index 000000000..33c0d32c6 --- /dev/null +++ b/web/core/modules/media/src/MediaForm.php @@ -0,0 +1,77 @@ +entity->bundle->entity; + + if ($this->operation === 'edit') { + $form['#title'] = $this->t('Edit %type_label @label', [ + '%type_label' => $media_type->label(), + '@label' => $this->entity->label(), + ]); + } + + // Media author information for administrators. + if (isset($form['uid']) || isset($form['created'])) { + $form['author'] = [ + '#type' => 'details', + '#title' => $this->t('Authoring information'), + '#group' => 'advanced', + '#attributes' => [ + 'class' => ['media-form-author'], + ], + '#weight' => 90, + '#optional' => TRUE, + ]; + } + + if (isset($form['uid'])) { + $form['uid']['#group'] = 'author'; + } + + if (isset($form['created'])) { + $form['created']['#group'] = 'author'; + } + + $form['#attached']['library'][] = 'media/form'; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + $saved = parent::save($form, $form_state); + $context = ['@type' => $this->entity->bundle(), '%label' => $this->entity->label()]; + $logger = $this->logger('media'); + $t_args = ['@type' => $this->entity->bundle->entity->label(), '%label' => $this->entity->label()]; + + if ($saved === SAVED_NEW) { + $logger->notice('@type: added %label.', $context); + drupal_set_message($this->t('@type %label has been created.', $t_args)); + } + else { + $logger->notice('@type: updated %label.', $context); + drupal_set_message($this->t('@type %label has been updated.', $t_args)); + } + + $form_state->setRedirectUrl($this->entity->toUrl('canonical')); + return $saved; + } + +}