Created
September 26, 2019 14:49
-
-
Save cdw9/71a4f79829963e2492eb89050427cbfb to your computer and use it in GitHub Desktop.
Plone 4 - Add valid_tags to the safe_html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<metadata> | |
<version>002</version> | |
</metadata> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from plone.app.controlpanel.filter import FilterControlPanelAdapter | |
from Products.CMFCore.utils import getToolByName | |
def html_filtering(context=None): | |
"""Change the HTML Filtering settings | |
""" | |
fcpa = FilterControlPanelAdapter(context) | |
transform = getattr(getToolByName(context, 'portal_transforms'), 'safe_html') | |
new_tags = ['button', 'script', 'form'] # include any others here | |
nasty_tags = dict(transform.get_parameter_value('nasty_tags')) | |
valid_tags = dict(transform.get_parameter_value('valid_tags')) | |
for tag in new_tags: | |
if tag in valid_tags: | |
continue | |
if tag in nasty_tags: | |
del nasty_tags[tag] | |
valid_tags[tag] = 1 | |
fcpa._settransform(valid_tags=valid_tags) | |
fcpa._settransform(nasty_tags=nasty_tags) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configure | |
xmlns="http://namespaces.zope.org/zope" | |
xmlns:genericsetup="http://namespaces.zope.org/genericsetup" | |
i18n_domain="project.policy"> | |
<genericsetup:upgradeStep | |
source="001" | |
destination="002" | |
sortkey="10" | |
title="Change HTML Filter settings" | |
description="" | |
profile="project.policy:default" | |
handler="project.policy.upgrades.html_filtering" | |
/> | |
</configure> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
version
in metadata.xml should increment from whatever you have there now. The old and new values should match what you put into the zcmlsource
anddestination
.Don't remove any other code that may already be in these files.