diff core/modules/media/src/MediaForm.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
line wrap: on
line diff
--- a/core/modules/media/src/MediaForm.php	Tue Jul 10 15:07:59 2018 +0100
+++ b/core/modules/media/src/MediaForm.php	Thu Feb 28 13:21:36 2019 +0000
@@ -59,20 +59,29 @@
    */
   public function save(array $form, FormStateInterface $form_state) {
     $saved = parent::save($form, $form_state);
-    $context = ['@type' => $this->entity->bundle(), '%label' => $this->entity->label()];
+    $context = ['@type' => $this->entity->bundle(), '%label' => $this->entity->label(), 'link' => $this->entity->toLink($this->t('View'))->toString()];
     $logger = $this->logger('media');
-    $t_args = ['@type' => $this->entity->bundle->entity->label(), '%label' => $this->entity->label()];
+    $t_args = ['@type' => $this->entity->bundle->entity->label(), '%label' => $this->entity->toLink($this->entity->label())->toString()];
 
     if ($saved === SAVED_NEW) {
       $logger->notice('@type: added %label.', $context);
-      drupal_set_message($this->t('@type %label has been created.', $t_args));
+      $this->messenger()->addStatus($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));
+      $this->messenger()->addStatus($this->t('@type %label has been updated.', $t_args));
     }
 
-    $form_state->setRedirectUrl($this->entity->toUrl('canonical'));
+    // Redirect the user to the media overview if the user has the 'access media
+    // overview' permission. If not, redirect to the canonical URL of the media
+    // item.
+    if ($this->currentUser()->hasPermission('access media overview')) {
+      $form_state->setRedirectUrl($this->entity->toUrl('collection'));
+    }
+    else {
+      $form_state->setRedirectUrl($this->entity->toUrl());
+    }
+
     return $saved;
   }