Replace files directly from file widget

Created on 29 July 2022, over 2 years ago
Updated 2 March 2024, 9 months ago

Problem/Motivation

It would be very good to have a possibility to replace files inline using file upload widget direct in a form. (e.g. directly on media detail pages)
Currently it's possible from files view page only.

Steps to reproduce

N/A

Proposed resolution

Add a hook to alter the file upload widget.

Remaining tasks

See the comments.

User interface changes

See screenshot above.

API changes

N/A

Data model changes

N/A

Feature request
Status

Needs review

Version

1.0

Component

User interface

Created by

🇦🇹Austria granik Vienna

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • 🇪🇸Spain guardiola86

    So this works, thanks, but I'm just wondering if we should add a message saying that the file name should be the same or it won't be replaced?

  • 🇪🇸Spain guardiola86

    In this patch, I'm just updating the file description so the user knows the file name must be the same.

  • 🇦🇹Austria granik Vienna

    Update: I opened a merge request to add new features:

    - now the inline link can be displayed for each inline widget separately
    - module settings form added, inline link can be enabled for all widgets, overriding single widgets settings
    - this also supported in D10

    The replace link now looks like:

    See File rename module I maintain, these features also implemented there.

    Also attach the patch just in case, to make possible to use it with composer.

  • Status changed to Needs work over 1 year ago
  • 🇦🇹Austria granik Vienna

    @guardiola86 the uploaded file is renamed automatically, so the new file has the same name even though it was uploaded with another name. I think it's caching issue, so after replacing the widget shows the old file instead and sometimes the page force reload is required.

    I think we don't need a message there, but I'm not sure how to solve this caching issue, maybe the cache tag of media should be invalidated?
    Nice catch. Thanks, @guardiola86. So I'll change the status for now.

  • Status changed to Needs review over 1 year ago
  • #17 in drupal 9.5.4 when using the light theme now the location of the buttons looks like this as in the image

  • 🇦🇹Austria granik Vienna

    @Nelo_Drup, have you applied the right patch? The red button in the bottom comes from the old one (comment #11), I'm sure.
    Look at the patch in the comment #16. Maybe cache flush is required.

  • #20 thanks and clarifying for those who update patch #16, now you will see 2 options, one to activate it in a general way as seen in the image and another to activate it specifically for some fields as seen in this image

  • Hello,

    Great module and great patch, thank you.
    I can't make it work on Adminimal Theme and I can't see why the hooks are not taken into account. Any help would be much appreciated.

  • 🇦🇹Austria granik Vienna

    @plusproduit could you please provide some info about your environment? What drupal version do you use?

  • 🇧🇪Belgium stred

    Hi,
    This new patch fixes the $request_destination that did not take in account the webroot. The 'Replace' link is displayed on Claro theme but not on Seven for instance (D 9.5.9), tried to fix that but no luck.

  • Status changed to Needs work over 1 year ago
  • 🇦🇹Austria granik Vienna

    Thanks @stred. But I guess you made a mistake in your patch, so it doesn't apply. I rerolled your patch and also added an interdiff.

    The 'Replace' link is displayed on Claro theme but not on Seven for instance (D 9.5.9), tried to fix that but no luck.

    I guess @plusproduit has the same issue. I have then to check it. Thx for the info!

  • Hello, I have a question to apply this patch, should I put each patch one by one or just the last one?

  • 🇦🇹Austria granik Vienna

    @Nelo_Drup, the last one #27 is the latest. It has some issues with Seven-based admin themes. You can also try #11 or #14, it's the old one, but it seems to have no theme problems, but has potential D10 issues. You can apply only one of them.

    I will work on this issue as soon as I have a bit more time for community work.

  • @granik Thanks for answering

  • Status changed to Needs review 10 months ago
  • 🇦🇹Austria granik Vienna

    Updated merge request, updated patch. See also last changes in File rename module dev version.

  • @granik Everything works fine except in the paragraphs there nothing changes

  • 🇦🇹Austria granik Vienna

    @Nelo_Drup, could you please add a bug report issue to file_rename issue queue, because that module's feature was a prototype for file_replace patch. Better with steps to reproduce, thank you!

  • @granik Hello, it seems that when you replace the image using this patch, the previous image is not changed until you clear the page's cache.

Production build 0.71.5 2024