Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix placeholder image in WYSIWYG editor when using a different admin theme #4240

Merged
merged 1 commit into from
Oct 20, 2024

Conversation

Caprico85
Copy link
Contributor

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:

image

If you have set a different admin theme, a broken image will be shown instead:

image

Or worse, if no width and height is set in the generated <img ...> tag, nothing will be shown at all:

image

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:

<p><img src="{{media url="wysiwyg/test.jpg"}}" alt=""></p>

To resolve the {{media}} tag, the editor sends a request to the server:

image

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:

public function getSkinImagePlaceholderPath()
{
    return Mage::getModel('core/design_package')->getSkinBaseDir(['_area' => 'adminhtml']) . DS .
        self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_FILE;
}

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 the default admin theme. But to correctly support other admin themes, is has to take fallbacks to the default theme into account. Using getFilename(), as in this PR, fixes that.

Manual testing scenarios (*)

  1. On a CMS page, product or anywhere else where you can use the WYSIWYG editor, add an image to the content and save.

image

  1. Delete the newly uploaded image from the folder media/wysiwyg/.

  2. Refresh the admin page. You will see the placeholder image as expected (as we have not yet set an admin theme)

image

  1. Set a different admin theme by setting this in your app/etc/local.xml:
<config>
    <stores>
        <admin>
            <design>
                <theme>
                    <default>mytheme</default>
                </theme>
            </design>
        </admin>
    </stores>
</config>

You don't need to create any directories. All file requests will transparently fall back to the default theme (well, almost all).

  1. Clear the config cache.

  2. Reload the admin page where you added the image. You will see a broken image.

image

  1. Apply my PR. The placeholder image is back.

(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 (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
  • Add yourself to contributors list

@github-actions github-actions bot added the Component: Cms Relates to Mage_Cms label Oct 2, 2024
@sreichel
Copy link
Contributor

sreichel commented Oct 3, 2024

@Hanmac @theroch please re-check admin-template fall-back PR (we talked about). May it fixes this too.

@addison74 addison74 merged commit e95ba6c into OpenMage:main Oct 20, 2024
18 checks passed
fballiano added a commit to MahoCommerce/maho that referenced this pull request Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Cms Relates to Mage_Cms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants