Skip to content
Snippets Groups Projects
Commit 5711f21d authored by Andrei Mateescu's avatar Andrei Mateescu Committed by timmillwood
Browse files

Issue #2803935 by amateescu: Fix TrashManagerInterface::trash() and...

Issue #2803935 by amateescu: Fix TrashManagerInterface::trash() and ::restore() to not return boolean values
parent 3418a3dd
No related branches found
No related tags found
No related merge requests found
...@@ -106,18 +106,19 @@ class TrashDeleteController extends ControllerBase { ...@@ -106,18 +106,19 @@ class TrashDeleteController extends ControllerBase {
return $this->entityFormBuilder->getForm($entity, 'delete'); return $this->entityFormBuilder->getForm($entity, 'delete');
} }
if ($this->trashManager->trash($entity)) { $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() drupal_set_message($this->t('The @entity %label has been moved to the trash. <a href=":undo-page">Undo</a>', [
->getLabel(), '@entity' => $entity->getEntityType()
'%label' => $entity->label(), ->getLabel(),
':undo-page' => Url::fromRoute('restore.form', [ '%label' => $entity->label(),
'entity_type_id' => $entity->getEntityTypeId(), ':undo-page' => Url::fromRoute('restore.form', [
'entity_id' => $entity->id(), 'entity_type_id' => $entity->getEntityTypeId(),
])->toString(), 'entity_id' => $entity->id(),
])); ])->toString(),
} ]));
$redirect_url = $this->getRedirectUrl($entity); $redirect_url = $this->getRedirectUrl($entity);
return $this->redirect($redirect_url->getRouteName(), $redirect_url->getRouteParameters()); return $this->redirect($redirect_url->getRouteName(), $redirect_url->getRouteParameters());
} }
......
...@@ -116,14 +116,13 @@ class RestoreForm extends ConfirmFormBase { ...@@ -116,14 +116,13 @@ class RestoreForm extends ConfirmFormBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
if ($this->trashManager->restore($this->entity)) { $this->trashManager->restore($this->entity);
drupal_set_message(t('The @entity "@label" has been restored.', [ drupal_set_message(t('The @entity "@label" has been restored.', [
'@entity' => $this->entity->getEntityType() '@entity' => $this->entity->getEntityType()
->get('label'), ->get('label'),
'@label' => $this->entity->label(), '@label' => $this->entity->label(),
])); ]));
$form_state->setRedirect('trash.default', ['entity_type_id' => $this->entity->getEntityTypeId()]); $form_state->setRedirect('trash.default', ['entity_type_id' => $this->entity->getEntityTypeId()]);
}
} }
} }
...@@ -23,7 +23,7 @@ class TrashManager implements TrashManagerInterface { ...@@ -23,7 +23,7 @@ class TrashManager implements TrashManagerInterface {
*/ */
public function trash(ContentEntityInterface $entity) { public function trash(ContentEntityInterface $entity) {
$entity->set('moderation_state', TrashModerationState::TRASHED); $entity->set('moderation_state', TrashModerationState::TRASHED);
return (bool) $entity->save(); $entity->save();
} }
/** /**
...@@ -45,7 +45,7 @@ class TrashManager implements TrashManagerInterface { ...@@ -45,7 +45,7 @@ class TrashManager implements TrashManagerInterface {
$revision_id = reset($revision_ids); $revision_id = reset($revision_ids);
$content_moderation_state = $storage->loadRevision($revision_id); $content_moderation_state = $storage->loadRevision($revision_id);
$entity->set('moderation_state', $content_moderation_state->moderation_state->target_id); $entity->set('moderation_state', $content_moderation_state->moderation_state->target_id);
return (bool) $entity->save(); $entity->save();
} }
} }
...@@ -7,16 +7,19 @@ use Drupal\Core\Entity\ContentEntityInterface; ...@@ -7,16 +7,19 @@ use Drupal\Core\Entity\ContentEntityInterface;
interface TrashManagerInterface { 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); 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); public function restore(ContentEntityInterface $entity);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment