-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from eea/develop
Release
- Loading branch information
Showing
12 changed files
with
211 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Breadcrumbs""" | ||
|
||
# -*- coding: utf-8 -*- | ||
from Acquisition import aq_base | ||
from Acquisition import aq_inner | ||
from plone.app.layout.navigation.interfaces import INavigationRoot | ||
from plone.app.layout.navigation.root import getNavigationRoot | ||
from Products.CMFPlone import utils | ||
from Products.CMFPlone.browser.interfaces import INavigationBreadcrumbs | ||
from Products.CMFPlone.browser.navigation import get_view_url | ||
from Products.CMFPlone.defaultpage import check_default_page_via_view | ||
from Products.CMFPlone.interfaces import IHideFromBreadcrumbs | ||
from Products.Five import BrowserView | ||
from zope.component import getMultiAdapter | ||
from zope.interface import implementer | ||
|
||
|
||
@implementer(INavigationBreadcrumbs) | ||
class PhysicalNavigationBreadcrumbs(BrowserView): | ||
"""EEA Physical Navigation Breadcrumbs""" | ||
|
||
def breadcrumbs(self): | ||
"""breadcrumbs""" | ||
context = aq_inner(self.context) | ||
request = self.request | ||
container = utils.parent(context) | ||
_name, item_url = get_view_url(context) | ||
# EEA add portal_type info to breadcrumbs | ||
last_crumb = { | ||
"absolute_url": item_url, | ||
"Title": utils.pretty_title_or_id(context, context), | ||
"portal_type": context.portal_type, | ||
"nav_title": getattr(aq_base(context), "nav_title", ""), | ||
} | ||
|
||
if container is None: | ||
return (last_crumb,) | ||
|
||
# Replicate Products.CMFPlone.browser.navigation. | ||
# RootPhysicalNavigationBreadcrumbs.breadcrumbs() | ||
# cause it is not registered during tests | ||
if INavigationRoot.providedBy(context): | ||
return () | ||
|
||
view = getMultiAdapter((container, request), | ||
name="eea_breadcrumbs_view") | ||
base = tuple(view.breadcrumbs()) | ||
|
||
# Some things want to be hidden from the breadcrumbs | ||
if IHideFromBreadcrumbs.providedBy(context): | ||
return base | ||
|
||
rootPath = getNavigationRoot(context) | ||
itemPath = "/".join(context.getPhysicalPath()) | ||
|
||
# don't show default pages in breadcrumbs or pages above the navigation | ||
# root | ||
if not check_default_page_via_view( | ||
context, request | ||
) and not rootPath.startswith(itemPath): | ||
base += (last_crumb,) | ||
return base |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
""" EEA Actions overrides """ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:cache="http://namespaces.zope.org/cache" | ||
xmlns:plone="http://namespaces.plone.org/plone" | ||
xmlns:zcml="http://namespaces.zope.org/zcml" | ||
> | ||
|
||
<adapter | ||
factory=".get.EEAActions" | ||
name="actions" | ||
/> | ||
|
||
</configure> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Breadcrumbs""" | ||
|
||
from zope.component import getMultiAdapter | ||
from zope.component import adapter | ||
from zope.i18n import translate | ||
from zope.interface import implementer | ||
from zope.interface import Interface | ||
from plone.restapi.interfaces import IExpandableElement, IPloneRestapiLayer | ||
from plone.restapi.services.actions.get import Actions | ||
|
||
|
||
@implementer(IExpandableElement) | ||
@adapter(Interface, IPloneRestapiLayer) | ||
class EEAActions(Actions): | ||
"""EEA Actions""" | ||
|
||
def __call__(self, expand=False): | ||
""" """ | ||
result = {"actions": {"@id": | ||
f"{self.context.absolute_url()}/@actions"}} | ||
if not expand: | ||
return result | ||
|
||
context_state = getMultiAdapter( | ||
(self.context, self.request), name="plone_context_state" | ||
) | ||
|
||
categories = self.request.form.get("categories", self.all_categories) | ||
filtered_action_props = { | ||
"category", | ||
"link_target", | ||
"available", | ||
"visible", | ||
"allowed", | ||
"modal", | ||
} | ||
data = {} | ||
for category in categories: | ||
category_action_data = [] | ||
actions = context_state.actions(category=category) | ||
for action in actions: | ||
# EEA allow actions props to be served by the endpoint except | ||
# for the ones listed in filtered_action_props | ||
action_data = { | ||
key: translate(value, context=self.request) | ||
if key == "title" | ||
else value | ||
for key, value in action.items() | ||
if key not in filtered_action_props | ||
} | ||
|
||
category_action_data.append(action_data) | ||
data[category] = category_action_data | ||
return {"actions": data} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
""" Breadcrumbs """ |
13 changes: 13 additions & 0 deletions
13
eea/volto/policy/restapi/services/breadcrumbs/configure.zcml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:cache="http://namespaces.zope.org/cache" | ||
xmlns:plone="http://namespaces.plone.org/plone" | ||
xmlns:zcml="http://namespaces.zope.org/zcml" | ||
> | ||
|
||
<adapter | ||
factory=".get.EEABreadcrumbs" | ||
name="breadcrumbs" | ||
/> | ||
|
||
</configure> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Breadcrumbs""" | ||
|
||
from zope.component import getMultiAdapter | ||
from zope.component import adapter | ||
from zope.interface import implementer | ||
from zope.interface import Interface | ||
from plone.restapi.interfaces import IExpandableElement, IPloneRestapiLayer | ||
from plone.restapi.services.breadcrumbs.get import Breadcrumbs | ||
|
||
|
||
@implementer(IExpandableElement) | ||
@adapter(Interface, IPloneRestapiLayer) | ||
class EEABreadcrumbs(Breadcrumbs): | ||
"""EEA Breadcrumbs""" | ||
|
||
def __call__(self, expand=False): | ||
""" """ | ||
result = {"breadcrumbs": { | ||
"@id": f"{self.context.absolute_url()}/@breadcrumbs"}} | ||
if not expand: | ||
return result | ||
|
||
portal_state = getMultiAdapter( | ||
(self.context, self.request), name="plone_portal_state" | ||
) | ||
breadcrumbs_view = getMultiAdapter( | ||
(self.context, self.request), name="eea_breadcrumbs_view" | ||
) | ||
items = [] | ||
# EEA add portal_type info to breadcrumbs | ||
for crumb in breadcrumbs_view.breadcrumbs(): | ||
item = { | ||
"title": crumb["Title"], | ||
"portal_type": crumb.get("portal_type", ""), | ||
"@id": crumb["absolute_url"], | ||
} | ||
if crumb.get("nav_title", False): | ||
item.update({"title": crumb["nav_title"]}) | ||
|
||
items.append(item) | ||
|
||
result["breadcrumbs"]["items"] = items | ||
result["breadcrumbs"]["root"] = portal_state.navigation_root()\ | ||
.absolute_url() | ||
return result |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5.5 | ||
5.6 |