When a user who can't see unpublished entities unpublishes one, it redirects to the home page and displays a message.

This commit is contained in:
2021-09-17 15:04:43 +01:00
parent a4c02ed249
commit 8d2d095b8e
5 changed files with 44 additions and 9 deletions

View File

@ -55,17 +55,25 @@ class OCActivityForm extends ContentEntityForm {
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label Activity.', [
'%label' => $entity->label(),
drupal_set_message($this->t('Created the %bundle.', [
'%bundle' => $entity->bundle(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Activity.', [
'%label' => $entity->label(),
drupal_set_message($this->t('Saved the %bundle.', [
'%bundle' => $entity->bundle(),
]));
}
$form_state->setRedirect('entity.oc_activity.canonical', ['oc_activity' => $entity->id()]);
// If you have unpublished the entity and you can't see unpublished entities, redirect to a more informative message than just "Access Denied".
if (!$form_state->getValue('status')['value'] && !\Drupal::currentUser()->hasPermission('view unpublished activity entities')) {
drupal_set_message($this->t('The %bundle is now unpublished & hidden from you.', [
'%bundle' => $entity->bundle(),
]));
$form_state->setRedirect('<front>');
} else {
$form_state->setRedirect('entity.oc_activity.canonical', ['oc_activity' => $entity->id()]);
}
}
}