When you delete an entity and trash is support for the type, you now get a message that is translable, which is fine of course.

However, I wonder whether it might be interesting to only override the message when you actually have access to restore the trashed entity? It might be a bit confusing for someone to read 'You can restore it from the trash at a later date if necessary' and not having any clue what this trash is in fact.

Marking as minor, I'd be fine even if you would close this as a won't fix since I could easily swap the hook and do it myself :)

Comments

swentel created an issue. See original summary.

swentel’s picture

Issue summary: View changes
amateescu’s picture

I think it makes perfect sense to only show the last part of the message ("You can restore them from the trash at a later date if necessary.") if the user has permission to restore entities of that type :)

We should also change the first part of the message and not link to the Trash page if the user doesn't have the access trash permission.

swentel’s picture

Status: Active » Needs review
StatusFileSize
new2.95 KB

Patch attached.

While the message is fine now in case you do not have any permissions at all for trash, it feels a bit weird when, say, you can restore, but not view the trash bin. Also, I'm not sure if this by design, you seem to need to have the 'View deleted entities' permission as well to be able to restore?

Feedback welcome!

amateescu’s picture

Status: Needs review » Needs work
  1. +++ b/trash.module
    @@ -203,8 +203,13 @@ function trash_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    +  if (isset($form['description']['#markup']) && $form['description']['#markup'] instanceof TranslatableMarkup && ($has_trash_access || $has_restore_access)) {
    

    This means that the message won't change if the user can't access trash or can't restore entities. I think we still need to let them know that the entity is going to the trash rather than being (permanently) deleted.

  2. +++ b/trash.module
    @@ -212,12 +217,25 @@ function trash_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    +        $form['description']['#markup'] = t($entity_delete_label, $params);
    ...
    +        $form['description']['#markup'] = t($entity_multiple_delete_label, $params);
    

    t() can't translate variables, we need to wrap each message above in t() calls :)

swentel’s picture

Status: Needs work » Needs review
StatusFileSize
new2.36 KB

I had no clue t couldn't do that, after 15 years I think, my god :)

Simplified the patch, no interdiff because it's totally different.
The permission now checks 'restore entity_type_id entities', 'access trash' and 'view deleted entities' because without those 3, it's not useful to link or have a message about restore.

swentel’s picture

StatusFileSize
new2.37 KB

Crap, forget one line to pass one $params

amateescu’s picture

StatusFileSize
new2.02 KB
new2.46 KB

Tweaked the patch a bit to follow a "highest" to "lowest" access level:

- if the user has restore access, having "view deleted" is (logically) implied, so we show the full message
- if the user has only view trash access, we hide the "restore" part of the message and link to the trash page
- if the user has no access, we don't link to the trash page anymore

amateescu’s picture

Category: Feature request » Task
Priority: Minor » Normal
StatusFileSize
new2.01 KB
new976 bytes

Updated the permission needed for the second case.

  • amateescu committed 19771aae on 3.x
    Issue #3408762 by swentel, amateescu: Different message on delete form...
amateescu’s picture

Status: Needs review » Fixed

Committed #9 to 3.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.