Different message on delete form depending on restore permission

Created on 14 December 2023, about 1 year ago
Updated 8 April 2024, 9 months ago

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 :)

📌 Task
Status

Fixed

Version

3.0

Component

Code

Created by

🇧🇪Belgium swentel

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @swentel
  • 🇷🇴Romania amateescu

    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.

  • Status changed to Needs review 12 months ago
  • 🇧🇪Belgium swentel

    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 'View deleted entities' permission as well to be able to restore?

    Feedback welcome!

  • Status changed to Needs work 12 months ago
  • 🇷🇴Romania amateescu
    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 :)

  • Status changed to Needs review 12 months ago
  • 🇧🇪Belgium swentel

    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.

  • 🇧🇪Belgium swentel

    Crap, forget one line to pass one $params

  • 🇷🇴Romania amateescu

    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 deleted 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

  • 🇷🇴Romania amateescu

    Updated the permission needed for the second case.

    • amateescu committed 19771aae on 3.x
      Issue #3408762 by swentel, amateescu: Different message on delete form...
  • Status changed to Fixed 9 months ago
  • 🇷🇴Romania amateescu

    Committed #9 to 3.x, thanks!

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

Production build 0.71.5 2024