From 5711f21dcbbd57133bf864cac0479311b5497c67 Mon Sep 17 00:00:00 2001
From: amateescu <amateescu@729614.no-reply.drupal.org>
Date: Wed, 21 Sep 2016 15:59:30 +0100
Subject: [PATCH] Issue #2803935 by amateescu: Fix
 TrashManagerInterface::trash() and ::restore() to not return boolean values

---
 src/Controller/TrashDeleteController.php | 23 ++++++++++++-----------
 src/Form/RestoreForm.php                 | 15 +++++++--------
 src/TrashManager.php                     |  4 ++--
 src/TrashManagerInterface.php            | 11 +++++++----
 4 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/src/Controller/TrashDeleteController.php b/src/Controller/TrashDeleteController.php
index 216ad00..65eeb1e 100644
--- a/src/Controller/TrashDeleteController.php
+++ b/src/Controller/TrashDeleteController.php
@@ -106,18 +106,19 @@ class TrashDeleteController extends ControllerBase {
       return $this->entityFormBuilder->getForm($entity, 'delete');
     }
 
-    if ($this->trashManager->trash($entity)) {
-      drupal_set_message($this->t('The @entity %label has been moved to the trash. <a href=":undo-page">Undo</a>', [
-        '@entity' => $entity->getEntityType()
-          ->getLabel(),
-        '%label' => $entity->label(),
-        ':undo-page' => Url::fromRoute('restore.form', [
-          'entity_type_id' => $entity->getEntityTypeId(),
-          'entity_id' => $entity->id(),
-        ])->toString(),
-      ]));
-    }
+    $this->trashManager->trash($entity);
+
+    drupal_set_message($this->t('The @entity %label has been moved to the trash. <a href=":undo-page">Undo</a>', [
+      '@entity' => $entity->getEntityType()
+        ->getLabel(),
+      '%label' => $entity->label(),
+      ':undo-page' => Url::fromRoute('restore.form', [
+        'entity_type_id' => $entity->getEntityTypeId(),
+        'entity_id' => $entity->id(),
+      ])->toString(),
+    ]));
     $redirect_url = $this->getRedirectUrl($entity);
+
     return $this->redirect($redirect_url->getRouteName(), $redirect_url->getRouteParameters());
   }
 
diff --git a/src/Form/RestoreForm.php b/src/Form/RestoreForm.php
index 166ab96..28e0725 100644
--- a/src/Form/RestoreForm.php
+++ b/src/Form/RestoreForm.php
@@ -116,14 +116,13 @@ class RestoreForm extends ConfirmFormBase {
    * {@inheritdoc}
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
-    if ($this->trashManager->restore($this->entity)) {
-      drupal_set_message(t('The @entity "@label" has been restored.', [
-        '@entity' => $this->entity->getEntityType()
-          ->get('label'),
-        '@label' => $this->entity->label(),
-      ]));
-      $form_state->setRedirect('trash.default', ['entity_type_id' => $this->entity->getEntityTypeId()]);
-    }
+    $this->trashManager->restore($this->entity);
+    drupal_set_message(t('The @entity "@label" has been restored.', [
+      '@entity' => $this->entity->getEntityType()
+        ->get('label'),
+      '@label' => $this->entity->label(),
+    ]));
+    $form_state->setRedirect('trash.default', ['entity_type_id' => $this->entity->getEntityTypeId()]);
   }
 
 }
diff --git a/src/TrashManager.php b/src/TrashManager.php
index 932eeb6..5075fea 100644
--- a/src/TrashManager.php
+++ b/src/TrashManager.php
@@ -23,7 +23,7 @@ class TrashManager implements TrashManagerInterface {
    */
   public function trash(ContentEntityInterface $entity) {
     $entity->set('moderation_state', TrashModerationState::TRASHED);
-    return (bool) $entity->save();
+    $entity->save();
   }
 
   /**
@@ -45,7 +45,7 @@ class TrashManager implements TrashManagerInterface {
     $revision_id = reset($revision_ids);
     $content_moderation_state = $storage->loadRevision($revision_id);
     $entity->set('moderation_state', $content_moderation_state->moderation_state->target_id);
-    return (bool) $entity->save();
+    $entity->save();
   }
 
 }
diff --git a/src/TrashManagerInterface.php b/src/TrashManagerInterface.php
index afdc9ca..8cdcba3 100644
--- a/src/TrashManagerInterface.php
+++ b/src/TrashManagerInterface.php
@@ -7,16 +7,19 @@ use Drupal\Core\Entity\ContentEntityInterface;
 interface TrashManagerInterface {
 
   /**
-   * @param \Drupal\Core\Entity\ContentEntityInterface $entity
+   * Moves an entity to trash.
    *
-   * @return bool
+   * @param \Drupal\Core\Entity\ContentEntityInterface $entity
+   *   A content entity object.
    */
   public function trash(ContentEntityInterface $entity);
 
   /**
-   * @param \Drupal\Core\Entity\ContentEntityInterface $entity
+   * Restores an entity from trash.
    *
-   * @return bool
+   * @param \Drupal\Core\Entity\ContentEntityInterface $entity
+   *   A content entity object.
    */
   public function restore(ContentEntityInterface $entity);
+
 }
-- 
GitLab