Fix placeholder image in WYSIWYG editor when using a different admin theme #4240
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description (*)
A very long description for a very specific use case 😄.
If you insert an image into your content, but later you delete the image from the disk, the WYSIWYG editor shows a placeholder image:
If you have set a different admin theme, a broken image will be shown instead:
Or worse, if no width and height is set in the generated <img ...> tag, nothing will be shown at all:
I would expect the placeholder image to always be shown, no matter which admin theme is used
This is caused as follows:
The WYSIWYG editor generates the HTML code like this:
To resolve the {{media}} tag, the editor sends a request to the server:
The request will be handled in Mage_Adminhtml_Cms_WysiwygController::directiveAction(). There, the placeholder image will be used if the original image cannot be found. The path to the placeholder image is generated like this:
This is the problem. It takes the skin directory of the current theme (
skin/adminhtml/default/mytheme/
) and concatenates the path to the placeholder image. This works fine for thedefault
admin theme. But to correctly support other admin themes, is has to take fallbacks to the default theme into account. UsinggetFilename()
, as in this PR, fixes that.Manual testing scenarios (*)
Delete the newly uploaded image from the folder media/wysiwyg/.
Refresh the admin page. You will see the placeholder image as expected (as we have not yet set an admin theme)
You don't need to create any directories. All file requests will transparently fall back to the default theme (well, almost all).
Clear the config cache.
Reload the admin page where you added the image. You will see a broken image.
(for extra fun, subscribe to exception mails in errors/local.xml and get email bombed whenever somebody edits a page with broken images)
Contribution checklist (*)