diff --git a/CHANGES.rst b/CHANGES.rst index 2e0a4255..9c87a702 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,12 @@ Changelog properties (see https://github.com/plone/Products.CMFPlone/issues/216). [jcerjak] +- use livesearch pattern + [vangheem] + +- use configuration registry pattern options + [vangheem] + - Added support for site logos stored in the portal registry via the site control panel for the logo viewlet with a fallback to the ``OFS.Image`` based ``logo.png`` file. Removed support of long-gone diff --git a/plone/app/layout/globals/patterns_settings.py b/plone/app/layout/globals/patterns_settings.py index f72115d3..669bbd1f 100644 --- a/plone/app/layout/globals/patterns_settings.py +++ b/plone/app/layout/globals/patterns_settings.py @@ -2,12 +2,12 @@ from zope.interface import implements from zope.component import getAdapters -from zope.component.hooks import getSite from zope.publisher.browser import BrowserView from .interfaces import IPatternsSettingsRenderer from Products.CMFPlone.interfaces import IPatternsSettings - -import json +from plone.registry.interfaces import IRegistry +from zope.component import getUtility +from zope.component import getMultiAdapter class PatternsSettings(BrowserView): @@ -17,20 +17,28 @@ class PatternsSettings(BrowserView): implements(IPatternsSettingsRenderer) def __call__(self): - modal_options = { - 'actionOptions': { - 'displayInModal': False, - } - } - base_url = getSite().absolute_url() + portal_state = getMultiAdapter( + (self.context, self.request), name=u'plone_portal_state') + # do not use getSite because it's possible it could be different + # than the actual portal url + base_url = portal_state.portal_url() result = { - 'data-pat-modal': json.dumps(modal_options), 'data-base-url': self.context.absolute_url(), 'data-portal-url': base_url, 'data-i18ncatalogurl': base_url + '/plonejsi18n' } + + # first, check for any adapters that need pattern data defined adapters = getAdapters((self.context, self.request, None), IPatternsSettings) [result.update(x[1]()) for x in adapters] - return result + # Resources Registered UI patterns can override adapters + registry = getUtility(IRegistry) + try: + pattern_options = registry['plone.patternoptions'] + except (AttributeError, KeyError): + pattern_options = {} + for key, value in pattern_options.items(): + result['data-pat-' + key] = value + return result diff --git a/plone/app/layout/globals/tests/test_pattern_settings.py b/plone/app/layout/globals/tests/test_pattern_settings.py new file mode 100644 index 00000000..a17cc1ab --- /dev/null +++ b/plone/app/layout/globals/tests/test_pattern_settings.py @@ -0,0 +1,33 @@ +from plone.app.layout.globals.tests.base import GlobalsTestCase +from plone.app.layout.globals.patterns_settings import PatternsSettings +from plone.registry.interfaces import IRegistry +from zope.component import getUtility + + +class TestPatternSettings(GlobalsTestCase): + """Ensure that the basic redirector setup is successful. + """ + + def testShouldReturnCorrectType(self): + settings = PatternsSettings(self.folder, self.app.REQUEST) + result = settings() + self.assertEquals(type(result), dict) + for key, value in result.items(): + self.assertTrue(isinstance(key, basestring)) + self.assertTrue(isinstance(value, basestring)) + + def testUrls(self): + settings = PatternsSettings(self.folder, self.app.REQUEST) + result = settings() + self.assertEquals(result['data-base-url'], self.folder.absolute_url()) + self.assertEquals(result['data-portal-url'], self.portal.absolute_url()) + + def testPatternOptions(self): + registry = getUtility(IRegistry) + registry['plone.patternoptions'] = { + 'foo': u'{"foo": "bar"}' + } + + settings = PatternsSettings(self.folder, self.app.REQUEST) + result = settings() + self.assertEquals(result['data-pat-foo'], u'{"foo": "bar"}') \ No newline at end of file diff --git a/plone/app/layout/links/viewlets.py b/plone/app/layout/links/viewlets.py index 3ec12839..48d15343 100644 --- a/plone/app/layout/links/viewlets.py +++ b/plone/app/layout/links/viewlets.py @@ -112,12 +112,13 @@ def update(self): settings = registry.forInterface(ISiteSyndicationSettings) except KeyError: return - for uid in settings.site_rss_items: - obj = uuidToObject(uid) - if obj is not None: - self.rsslinks.extend(self.getRssLinks(obj)) - self.rsslinks.extend(self.getRssLinks( - self.portal_state.portal())) + if settings.site_rss_items: + for uid in settings.site_rss_items: + obj = uuidToObject(uid) + if obj is not None: + self.rsslinks.extend(self.getRssLinks(obj)) + self.rsslinks.extend(self.getRssLinks( + self.portal_state.portal())) else: if util.context_enabled(): self.rsslinks.extend(self.getRssLinks(self.context)) diff --git a/plone/app/layout/viewlets/common.py b/plone/app/layout/viewlets/common.py index 0f653050..4a05b727 100644 --- a/plone/app/layout/viewlets/common.py +++ b/plone/app/layout/viewlets/common.py @@ -17,6 +17,7 @@ from Products.CMFCore.utils import getToolByName from Products.CMFPlone.interfaces import ISiteSchema +from Products.CMFPlone.interfaces import ISearchSchema from Products.CMFPlone.utils import safe_unicode from Products.CMFPlone.interfaces import IPloneSiteRoot from Products.Five.browser import BrowserView @@ -175,13 +176,9 @@ def update(self): context_state = getMultiAdapter((self.context, self.request), name=u'plone_context_state') - props = getToolByName(self.context, 'portal_properties') - livesearch = props.site_properties.getProperty( - 'enable_livesearch', False) - if livesearch: - self.search_input_id = "searchGadget" - else: - self.search_input_id = "nolivesearchGadget" # don't use "" here! + registry = getUtility(IRegistry) + search_settings = registry.forInterface(ISearchSchema, prefix='plone') + self.livesearch = search_settings.enable_livesearch folder = context_state.folder() self.folder_path = '/'.join(folder.getPhysicalPath()) diff --git a/plone/app/layout/viewlets/searchbox.pt b/plone/app/layout/viewlets/searchbox.pt index 879a6d72..bde537c0 100644 --- a/plone/app/layout/viewlets/searchbox.pt +++ b/plone/app/layout/viewlets/searchbox.pt @@ -1,30 +1,30 @@