mgraf
(Michael)
1
Is there a way to modify patterns options for the complete site - for all "relateditems" fields?
I want to extend the Favorites-Dropdown...
What I already tried:
1- Resource-Registry - pattern options
Write options to body-Attributes, does not work. Settings in Widgets are used
2- Adapt IPatternsSettings (from CMFPlone) does not work, writes to body-Attributes. Settings in Widgets are used
mgraf
(Michael)
2
Ok, its working now
Not working actually:
- translation of dropdown items
- Add items without "copying" default items
- Update/Change default items
This is my working code:
configure.zcml
<adapter
for="* * *"
factory=".adapters.PatternsAttributes"
provides="Products.CMFPlone.interfaces.IPatternsSettings"
name="patternslib" />
adapters .py
# -*- coding: utf-8 -*-
# Standard Library
import json
# Plone
from plone import api
from Products.CMFPlone.utils import get_portal
# Package
from . import message_factory as _
class PatternsAttributes(object):
def __init__(self, context, request, field):
self.request = request
self.context = context
self.field = field
def __call__(self):
portal = get_portal()
portal_url = portal.absolute_url()
root = '/'.join(
api.portal.get_navigation_root(self.context).getPhysicalPath())
current_path = self.context.absolute_url()[len(portal_url):]
current = dict({
'path': current_path,
'title': _(u'Current Content')
})
nav_root = dict({
'path': root,
'title': _(u'Frontpage')
})
mediacenter = dict({
'path': '{}/mediathek'.format(root),
'title': _(u'Media Center')
})
options = list()
options.append(current)
options.append(nav_root)
options.append(mediacenter)
favorites = dict({'favorites': options})
return {'data-pat-relateditems': json.dumps(favorites)}
Links: