Repository: plone.app.textfield
Branch: refs/heads/master
Date: 2014-11-14T13:22:47+01:00
Author: Johannes Raggam (thet) <raggam-nl@adm.at>
Commit: https://github.com/plone/plone.app.textfield/commit/55cb66d9ebdae5c7ee38cbb6714dd6c9230eaa95

For Plone 5, support getting markup control panel settings from the registry, while still supporting normal portal_properties access for Plone &lt; 5.

Files changed:
M docs/HISTORY.rst
M plone/app/textfield/utils.py

diff --git a/docs/HISTORY.rst b/docs/HISTORY.rst
index b9064fe..7da4a34 100644
--- a/docs/HISTORY.rst
+++ b/docs/HISTORY.rst
@@ -4,7 +4,9 @@ Changelog
 1.2.5 (unreleased)
 ------------------
 
-- Nothing changed yet.
+- For Plone 5, support getting markup control panel settings from the registry,
+  while still supporting normal portal_properties access for Plone < 5.
+  [thet]
 
 
 1.2.4 (2014-10-20)
diff --git a/plone/app/textfield/utils.py b/plone/app/textfield/utils.py
index e1a2172..9e7a1a2 100644
--- a/plone/app/textfield/utils.py
+++ b/plone/app/textfield/utils.py
@@ -1,6 +1,29 @@
 from zope.component.hooks import getSite
 from Products.CMFCore.utils import getToolByName
 
+try:
+    from Products.CMFPlone.interfaces import IMarkupSchema
+    from plone.registry.interfaces import IRegistry
+    from zope.component import getUtility
+    from zope.component.interfaces import ComponentLookupError
+except ImportError:
+    IMarkupSchema = None
+
+
+def markupRegistrySettings(context):
+    if not IMarkupSchema:
+        return None
+    try:
+        # get the new registry
+        registry = getUtility(IRegistry, context=context)
+        settings = registry.forInterface(
+            IMarkupSchema,
+            prefix='plone',
+        )
+    except (KeyError, ComponentLookupError):
+        settings = None
+    return settings
+
 
 # XXX this can probably be removed
 def getSiteEncoding(default='utf-8'):
@@ -13,24 +36,31 @@ def getAllowedContentTypes():
     """Get a set of allowed MIME types according to the portal_properties
     tool
     """
-
     site = getSite()
     if site is None:
         return None
 
-    portal_transforms = getToolByName(site, 'portal_transforms', None)
-    if portal_transforms is None:
-        return None
+    allowed_types = []
+    reg = markupRegistrySettings(site)
+    if reg:
+        allowed_types = reg.allowed_types
+    else:
+        portal_transforms = getToolByName(site, 'portal_transforms', None)
+        if portal_transforms is None:
+            return None
 
-    portal_properties = getToolByName(site, 'portal_properties', None)
-    if portal_properties is None:
-        return None
+        portal_properties = getToolByName(site, 'portal_properties', None)
+        if portal_properties is None:
+            return None
 
-    site_properties = portal_properties.get('site_properties', None)
-    if site_properties is None:
-        return None
+        site_properties = portal_properties.get('site_properties', None)
+        if site_properties is None:
+            return None
+
+        allowed = set(portal_transforms.listAvailableTextInputs())
+        forbidden = set(
+            site_properties.getProperty('forbidden_contenttypes', []))
 
-    allowed = set(portal_transforms.listAvailableTextInputs())
-    forbidden = set(site_properties.getProperty('forbidden_contenttypes', []))
+        allowed_types = allowed - forbidden
 
-    return allowed - forbidden
+    return allowed_types


Repository: plone.app.textfield
Branch: refs/heads/master
Date: 2014-11-14T13:23:59+01:00
Author: Johannes Raggam (thet) <raggam-nl@adm.at>
Commit: https://github.com/plone/plone.app.textfield/commit/9b9eff306fadeb2133e05be1824be7e0540e6b12

Remove utils.getSiteEncoding, which was deprecated and not used anywhere.

Files changed:
M plone/app/textfield/utils.py

diff --git a/plone/app/textfield/utils.py b/plone/app/textfield/utils.py
index 9e7a1a2..a4d7c2a 100644
--- a/plone/app/textfield/utils.py
+++ b/plone/app/textfield/utils.py
@@ -25,13 +25,6 @@ def markupRegistrySettings(context):
     return settings
 
 
-# XXX this can probably be removed
-def getSiteEncoding(default='utf-8'):
-    """Get the default site encoding
-    """
-    return 'utf-8'
-
-
 def getAllowedContentTypes():
     """Get a set of allowed MIME types according to the portal_properties
     tool