Skip to content

Instantly share code, notes, and snippets.

@cdw9
Created September 26, 2019 14:49
Show Gist options
  • Save cdw9/71a4f79829963e2492eb89050427cbfb to your computer and use it in GitHub Desktop.
Save cdw9/71a4f79829963e2492eb89050427cbfb to your computer and use it in GitHub Desktop.
Plone 4 - Add valid_tags to the safe_html
<?xml version="1.0"?>
<metadata>
<version>002</version>
</metadata>
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)
<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>
@cdw9
Copy link
Author

cdw9 commented Sep 26, 2019

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 zcml source and destination.

Don't remove any other code that may already be in these files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment