Skip to content

Commit

Permalink
Merge pull request #93 from plone/update-crumbs-nav
Browse files Browse the repository at this point in the history
add something meaningful for breadcrumbs and nav
  • Loading branch information
lukasgraf committed May 17, 2016
2 parents adc8a95 + 14f2e30 commit 72c1000
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
10 changes: 3 additions & 7 deletions docs/source/_json/components_breadcrumbs.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GET /plone/components_/breadcrumbs
GET /plone/front-page/components_/breadcrumbs
Accept: application/json

HTTP 200 OK
Expand All @@ -9,12 +9,8 @@ content-type: application/json
"data": {
"items": [
{
"title": "Junk",
"url": "http://plone/junk"
},
{
"title": "More Junk",
"url": "http://plone/junk/more-junk"
"title": "Welcome to Plone",
"url": "http://localhost:55001/plone/front-page"
}
]
},
Expand Down
37 changes: 25 additions & 12 deletions src/plone/restapi/services/components/get.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plone.rest import Service
from zope.component import getMultiAdapter
from zope.interface import implements
from zope.publisher.interfaces import IPublishTraverse

Expand Down Expand Up @@ -31,21 +32,33 @@ def _frame_component_items(self, items, component_id):
}
return component

def get_navigation(self):
tabs = getMultiAdapter((self.context, self.request),
name="portal_tabs_view")
result = []
for tab in tabs.topLevelTabs():
result.append({
'title': tab.get('title', tab.get('name')),
'url': tab['url'] + ''
})
return result

def get_breadcrumbs(self):
breadcrumbs_view = getMultiAdapter((self.context, self.request),
name="breadcrumbs_view")
result = []
for crumb in breadcrumbs_view.breadcrumbs():
result.append({
'title': crumb['Title'],
'url': crumb['absolute_url']
})
return result

def _render_component(self, component_id):
if component_id == 'navigation':
items = [
{'title': 'News',
'url': 'http://plone/news'},
{'title': 'Events',
'url': 'http://plone/events'}
]
items = self.get_navigation()
elif component_id == 'breadcrumbs':
items = [
{'title': 'Junk',
'url': 'http://plone/junk'},
{'title': 'More Junk',
'url': 'http://plone/junk/more-junk'}
]
items = self.get_breadcrumbs()
else:
raise NotImplementedError(
'This endpoint does not currently support the '
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/tests/test_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def test_documentation_components_navigation(self):
'components_navigation.json', response)

def test_documentation_components_breadcrumbs(self):
response = self.api_session.get('/components_/breadcrumbs')
response = self.api_session.get('/front-page/components_/breadcrumbs')
save_response_for_documentation(
'components_breadcrumbs.json', response)

Expand Down

0 comments on commit 72c1000

Please sign in to comment.