Only compatible with Claro (admin) theme?

Created on 13 July 2023, over 1 year ago
Updated 18 February 2024, 9 months ago

Problem/Motivation

When testing this module out, I found that the "rename" links only showed up when using the Claro (administration) theme.
They did not show up on the frontend of our site which is a sub-theme of Olivero.

Steps to reproduce

1. Enable module.
2. Use a theme other than Claro.
3. Visit a node with a file upload file. In our case the field allows multiple files. (I don't know whether this is significant).
4. Upload a file and save the node.
5. Edit the same node again.
6. The file shows up but does not have a "Rename" link.

I expected the "Rename" link to show up.

Proposed resolution

I noticed that the links showed up when logged in as an admin, and thought it was a permissions issue. After further investigation I realized it is due to differences between Claro and other themes.

I traced this to `web/core/themes/claro/templates/content-edit/file-managed-file.html.twig` which includes this code

{{ main_items.filename }}
{{ main_items|without('filename') }}

In contrast, `web/core/modules/file/templates/file-managed-file.html.twig` looks like this:

{{ element }}

It appears that code in claro.theme sets up the "main_items" array for use by its the template.

When I checked the file_rename code, I found that file_rename.module moves the links into this "main_items" array, in functions `file_rename_preprocess_image_widget` and `file_rename_preprocess_file_managed_file`. It does this regardless of which theme is being used.

The end effect is that the links show up in claro, but not other themes.

My local fix was to create mytheme/templates/file-managed-file.html.twig (by copying `web/core/modules/file/templates/file-managed-file.html.twig`) then add into it the line containing main_items, so that you have:

{{ element }}
{{ main_items|without('filename') }}

I don't know what the correct solution is. The way file_rename assumes that Claro is being used and puts the link within main_items seems problematic. Maybe it should detect the active theme, and only do this for Claro. Not elegant, but I can't think of a better solution.

🐛 Bug report
Status

Fixed

Version

1.0

Component

User interface

Created by

🇨🇦Canada jdhildeb

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

Comments & Activities

  • Issue created by @jdhildeb
  • 🇦🇹Austria granik Vienna

    @jdhildeb, thanks for creating this issue. I would say a good solution is adding a module setting "Rename link position" with options "under the widget" and "next to remove button". Also add a description that the second option can have display problems with non-claro themes. What do you think, is this a good solution?

  • 🇯🇵Japan ilfelice

    Howdy,

    I tested the solution (workaround?) proposed by @jdhildeb, and it worked, as in, the "Rename" button was displayed.

    This was on a Drupal 10 installation using the Bootstrap 3 theme.

    FWYW

  • 🇯🇵Japan ilfelice

    Howdy,

    Quick follow up on this issue.

    After updating my Drupal installation to 10.1.5, the rename link disappeared from the form widget.

    Since I am using a Bootstrap 3 subtheme, I resorted to modifying the Boostrap 3 image-widget.html.twig template in the subtheme.

    Specifically, I changed the line

    {{ data|without('preview') }}

    to

    {{ element|without('preview') }}

    Now the rename link is back, not in the ideal position (above the file link), but otherwise working fine, as in, serving its purpose.

    Thought I would share in case it helps anyone else.

    • granik committed 16fbaa0f on 1.0.x
      Issue #3374512 by jdhildeb, ilfelice, granik: Only compatible with Claro...
  • Status changed to Fixed 10 months ago
  • 🇦🇹Austria granik Vienna

    Fixed in dev version.

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

Production build 0.71.5 2024