Calculate file tokens using filename instead of uri field, add filename token w/o extension

Created on 20 January 2020, almost 5 years ago
Updated 4 March 2024, 10 months ago

I'm seeing a problem whereby the URI of the file is not present when bulk re-generating URL aliases for some of my images on my site and the URL alias pattern set to file/[file:basename] ends up with an empty value for the basename.

I cannot explain why or how the $file->uri->value is empty, but the file entity's view page still shows the image. Similarly, the edit page of the file entity has a "Filename" field that still has a value.

Its weird that regenerating URL aliases from images that may have missing URI's but still have a valid Filename field exposed on the edit form end up getting a url of file-0 file-1 file-2 successively due to the missing basename value.

I think it makes sense to use to $file->filename->value to calculate the basename field because it is less likely that the value will get overwritten or emptied from the database, unless specifically done so. And it also allows you to update the URL by changing a field on the edit form without actually having to upload a different file with a different name to change the URL. Whether or not this gets accepted is really up to the maintainer, but I'm providing a patch in case anyone else has this problem.

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ͺπŸ‡¨Ecuador jwilson3

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡¦Canada bohemier QuΓ©bec city, Qc

    This patch is very useful as it provides a filename token and clarifies what basename is (filename with extension).

  • First commit to issue fork.
  • Status changed to Needs work 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    Filename (no path, no extension) is definitely needed as a token, and this issue has the patch that does that. Maybe it needs to be done differently or the issue refocused, but it really is a key token to have.

Production build 0.71.5 2024