I had a problem with TinyMCE and the advanced image button (assume this it the same with the basic one, but I've not checked it). There's no extended_valid_elements array item that includes the img tag.

I've created a workaround for the issue, which I've verified, but it's a nasty hack:

sites/all/modules/wysiwyg/editors/tinymce.inc

Find the code that starts:

// Clean-up.
$init['extended_valid_elements'] = array_unique($init['extended_valid_elements']);

From what I can work out, this is used to make sure that any 'extended_valid_elements' that are added by plugins aren't duplicated. I found that adding in an extra line to allow for advanced image-formatting did the trick, changing the code to:

// Clean-up.
$init['extended_valid_elements'] = array('img[class|style|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name]');
$init['extended_valid_elements'] = array_unique($init['extended_valid_elements']);
$init['extended_valid_elements'] = array_unique($init['extended_valid_elements']);

This may have been solved in one of the dev versions, or I'm happy to submit a patch, if you can point me in the right direction for where this code should go. Seems like it should be included int he tinyMCE settings in WYSIWYG as the basic/advanced image buttons ship with the editor as standard.

Also, it looks like the code that the settings for $init['extended_valid_arguments'] is set to an empty array, when iterating through the user plugins. Might make sense for a global setting to include the standard tags used by the buttons that TinyMCE ships with.

Happy to help, if I can. Hope this is useful.

Toodle Pip

Sam
http://www.toodlepip.co.uk

Comments

sun’s picture

Title: TinyMCE 3.x & Advanced Image Button - CSS Styles Being Stripped » TinyMCE 3: extended_valid_elements merged wrongly

Yes, please supply a patch.

toodlepip’s picture

StatusFileSize
new707 bytes

Patch is attatched. This is my first attempt at creating one, so hope this is correct. Needs to be applied to: wysiwyg/editors/tinymce.inc file. Hope it helps.

sun’s picture

Version: 6.x-0.5 » 6.x-1.0

Sorry, but

+    // Nasty hack

in unacceptable. This patch probably breaks a bunch of other editor plugins, including the Image Assist plugin. A real fix should not be very hard (as long as you understand the syntax of those extended valid element definitions).

toodlepip’s picture

Sorry sun, I'm new to this, so forgive the newbie errors.

I wasn't sure whereabouts this code should go, as the Advanced Image feature is part of the core TinyMCE editor. The initialisation of $init seemed like the right place to put it, but the extended_valid_arguments element is reset when the info is called in from the plugins.

Should this code go into a separate file in the plugins directory, or wysiwyg.plugins.inc? Or somewhere else? Sorry if these are dumb questions.

sun’s picture

The location of the changes in your patch was (approximately) correct. However, your patch (even) starts with a comment that says "Nasty hack" -- Nasty hacks work for your particular use-case, but not for everyone else. The Advanced image plugin already defines the extended_valid_elements property. In your initial post you outlined that another plugin is also defining this poperty for the same HTML tag and TinyMCE uses the "wrong" definition (for the other plugin), which renders the Advanced image plugin non-functional. The proper solution for this bug is merge all extended_valid_elements definitions correctly, so if two plugins are defining it for the same HTML tag, the allowed (valid) attributes are appropriately merged into one element definition.

toodlepip’s picture

@sun Thanks for the feedback. Have done some more reading and my use case seems to be the same as the #287025: IMCE_Wysiwyg API bridge module which effectively solves the issue. I reckon this issue can be closed, if you're cool with it.

toodlepip’s picture

Status: Active » Closed (fixed)
sun’s picture

Status: Closed (fixed) » Active
hefox’s picture

Status: Active » Needs review
StatusFileSize
new2.29 KB

Patch assumes extended_valid_elements is array('font[face|size|color|style]', 'span[class|align|style]') and not array('font[face|size|color|style],span[class|align|style]') and thus changes where it is done like the later.