? ? Pending

User tests: Successful: Unsuccessful:

avatar joomdonation
joomdonation
19 Jul 2021

Pull Request for Issue #34810.

Summary of Changes

The value stored in media form field (at least for image) contains adapter information (for example, images/headers/blue-flower.jpg#joomlaImage://local-images/headers/blue-flower.jpg?width=700&height=180), thus file_exist checks on this line https://github.com/joomla/joomla-cms/blob/4.0-dev/layouts/joomla/form/field/media.php#L77 return false and it results in preview image is not being displayed properly as described in the issue #34810

This PR solves it by clean the value (removes adapter information) before file_exists check. A new method is added to MediaHelper class so that we can use on other places when it is needed (or even could be used by third party extensions developer - for example, we need to check and make sure the selected image is valid before resizing...)

Testing Instructions

  1. Look at #34810, confirm the issue
  2. Apply patch, confirm that the issue is sorted.
avatar joomdonation joomdonation - open - 19 Jul 2021
avatar joomdonation joomdonation - change - 19 Jul 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 19 Jul 2021
Category Layout Libraries
avatar richard67
richard67 - comment - 19 Jul 2021

@joomdonation I guess it was the auto correct by the spell checker which changed „preview“ to „previous“ if the title here.

avatar joomdonation joomdonation - change - 19 Jul 2021
Title
[4.0] Fix image previous for media form field
[4.0] Fix image preview for media form field
avatar joomdonation joomdonation - edited - 19 Jul 2021
avatar joomdonation
joomdonation - comment - 19 Jul 2021

@richard67 Thanks. Maybe it was a typo.

avatar joomdonation joomdonation - change - 19 Jul 2021
Labels Added: ?
avatar joomdonation
joomdonation - comment - 19 Jul 2021

@dgrammatiko Thanks. I didn't know that you need full value for preview

avatar dgrammatiko
dgrammatiko - comment - 19 Jul 2021

I didn't know that you need full value for preview

Actually, we don't, but changing the $src in that point changes also the value in the input (and I guess we need the full value there). Basically edit a banner select a new image, save close, reopen and save (you lose the extra bits), this is what the proposed change prevents (I have no clue if it will be a problem, just did run the code in my head, so I might be wrong)

avatar joomdonation
joomdonation - comment - 19 Jul 2021

Actually, we don't, but changing the $src in that point changes also the value in the input

Hmm. Change the $src variable won't change the value displaying in the input. The value in the input is still taken from $value variable, I think.

avatar dgrammatiko
dgrammatiko - comment - 19 Jul 2021

Hmm. Change the $src variable won't change the value displaying in the input. The value in the input is still taken from $value variable, I think.

You're right, I need more coffee, sorry

avatar joomdonation
joomdonation - comment - 19 Jul 2021

Hmm. Somehow, the src of the preview image still use the unclean value. Maybe you set it automatically base on the value from input in the JS code?

avatar dgrammatiko
dgrammatiko - comment - 19 Jul 2021

Hmm. Somehow, the src of the preview image still use the unclean value. Maybe you set it automatically base on the value from input in the JS code?

Yes, the preview src is just the source + Uri:root(true)

previewElement.src = /http/.test(value) ? value : Joomla.getOptions('system.paths').rootFull + value;

Now that I think about it it's good to have the same URL both from PHP and JS otherwise there will be 2 downloads for the same image

avatar joomdonation
joomdonation - comment - 19 Jul 2021

Main question here is we have source from php, then why do we need to calculate src js again?

avatar dgrammatiko
dgrammatiko - comment - 19 Jul 2021

Main question here is we have source from php, then why do we need to calculate src js again?

The update of the preview happens as part of the field's custom element initialization (connectedCallback()) and I guess the idea was to resolve external adapters here (but I doubt that the code does that). Anyways the line for triggering the JS resetting the preview html is here:

avatar dgrammatiko dgrammatiko - test_item - 21 Jul 2021 - Tested successfully
avatar dgrammatiko
dgrammatiko - comment - 21 Jul 2021

I have tested this item successfully on e904530


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/34833.

88d662a 21 Jul 2021 avatar Quy __
avatar richard67 richard67 - alter_testresult - 21 Jul 2021 - dgrammatiko: Tested successfully
avatar richard67
richard67 - comment - 21 Jul 2021

I've restored the previous test result since the change after that was only in a comment.

avatar Quy Quy - test_item - 22 Jul 2021 - Tested successfully
avatar Quy
Quy - comment - 22 Jul 2021

I have tested this item successfully on 88d662a


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/34833.

avatar Quy Quy - change - 22 Jul 2021
Status Pending Ready to Commit
avatar Quy
Quy - comment - 22 Jul 2021

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/34833.

avatar wilsonge wilsonge - change - 23 Jul 2021
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2021-07-23 21:32:59
Closed_By wilsonge
Labels Added: ?
avatar wilsonge wilsonge - close - 23 Jul 2021
avatar wilsonge wilsonge - merge - 23 Jul 2021
avatar wilsonge
wilsonge - comment - 23 Jul 2021

Thanks!

Add a Comment

Login with GitHub to post a comment