Skip to content

[EditInPlace] Fix bad HTML generation when there is HTML in the translation #259

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

Merged
merged 3 commits into from
Feb 25, 2019

Conversation

damienalexandre
Copy link
Contributor

@damienalexandre damienalexandre commented Sep 17, 2018

An error could occur when using Edit In Place with HTML in the translations:

Uncaught DOMException: Failed to execute 'setAttribute' on 'Element': 'show-for-custom-md"' is not a valid attribute name.
    at c.mount (http://notarealwebsite.com:8000/bundles/translation/js/content-tools.min.js?9:3:20706)
    at new c (http://notarealwebsite.com:8000/bundles/translation/js/content-tools.min.js?9:3:12341)
    at c._initRegions (http://notarealwebsite.com:8000/bundles/translation/js/content-tools.min.js?9:6:24008)
    at c.start (http://notarealwebsite.com:8000/bundles/translation/js/content-tools.min.js?9:6:20300)
    at b.<anonymous> (http://notarealwebsite.com:8000/bundles/translation/js/content-tools.min.js?9:6:14355)
    at b.a.dispatchEvent (http://notarealwebsite.com:8000/bundles/translation/js/content-tools.min.js?9:4:24074)
    at b.edit (http://notarealwebsite.com:8000/bundles/translation/js/content-tools.min.js?9:4:27817)
    at HTMLDivElement.<anonymous> (http://notarealwebsite.com:8000/bundles/translation/js/content-tools.min.js?9:4:29468)
c.mount @ content-tools.min.js?9:formatted:2749
c @ content-tools.min.js?9:formatted:2418
c._initRegions @ content-tools.min.js?9:formatted:6656
c.start @ content-tools.min.js?9:formatted:6508
(anonymous) @ content-tools.min.js?9:formatted:6251
a.dispatchEvent @ content-tools.min.js?9:formatted:4299
b.edit @ content-tools.min.js?9:formatted:4482
(anonymous) @ content-tools.min.js?9:formatted:4524

Is was caused by the Translator, as we transform the translation to wrap them in a x-trans HTML tag, and the translation is set as an attribute of that tag, the bundle was building invalid HTML.

This PR remove the ability to Edit In Place a translation where HTML has been put, and also add tests.

This PR fix the generated HTML output and adds tests.

@damienalexandre
Copy link
Contributor Author

This is going to fix #141.

Copy link
Member

@rvanlaak rvanlaak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure wo don't want contenttools to support certain html tags?

http://getcontenttools.com/demo

If so, it would be a pity that we can't support html translations. Disabling it for edit in place in that case is better as trying to support it.

@damienalexandre
Copy link
Contributor Author

You are right, we support HTML translations (we try to), as shown in the documentation: https://php-translation.readthedocs.io/en/latest/symfony/edit-in-place.html#the-editor-toolbox-for-html

editor.init('x-trans', 'data-key', function(domRegion) {
// true = fixture (string of text)
// false = classic HTML block
return domRegion.dataset.key.split('.').pop() !== 'html';
});

So the implementation is broken when the HTML contains attributes.

Just pushed another way to fix this that works with HTML translations! 👏 Thanks for your input @rvanlaak !

@damienalexandre damienalexandre changed the title [EditInPlace] Do not replace HTML translation with <x-trans> tag [EditInPlace] Fix bad HTML generation when there is HTML in the translation Sep 17, 2018
@Nyholm Nyholm dismissed rvanlaak’s stale review February 25, 2019 05:43

PR was updated

@Nyholm Nyholm merged commit 99f88a7 into master Feb 25, 2019
@Nyholm Nyholm deleted the fix/html-in-translation branch February 25, 2019 05:43
@Nyholm
Copy link
Member

Nyholm commented Feb 25, 2019

Thank you

Kocal pushed a commit to Kocal/symfony-bundle that referenced this pull request Mar 13, 2019
…lation (php-translation#259)

* [EditInPlace] Do not replace HTML translation with <x-trans> tag

* Fix the Coding Style as suggested by StyleCi

(too bad phpcsfixer is not part of the project)

* Instead of disabling HTML translations, just generate valid HTML
@odolbeau odolbeau mentioned this pull request Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants