We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
exclude_from_nav and show_excluded_items are not handled correctly in portal_tabs_view
### What I did:

Create a folder on top level and exclude id from navigation

### What I expect to happen:

the folder should disappear from global navigation **when I'm not inside it's context**

### What actually happened:

the folder is always in the navigation

### What version of Plone/ Addons I am using:

plone 5.2rc2

### REASON:

I'm fixing a bug found here: https://github.com/plone/plone.app.layout/issues/190
which leads to the same result in `portal_tabs_view` here https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/browser/navigation.py#L151-L153

if `show_excluded_items` is activated (which actually is the default setting) every item is shown regardless of `exclude_from_nav` setting. But what the setting claims is to show the excluded item only if you're inside of it.

PR is in preparation...

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `Products/CMFPlone/browser/navigation.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 from Acquisition import aq_base
3 from Acquisition import aq_inner
4 from plone.app.layout.navigation.interfaces import INavtreeStrategy
5 from plone.app.layout.navigation.navtree import buildFolderTree
6 from plone.app.layout.navigation.root import getNavigationRoot
7 from plone.registry.interfaces import IRegistry
8 from Products.CMFCore.utils import getToolByName
9 from Products.CMFPlone import utils
10 from Products.CMFPlone.browser.interfaces import INavigationBreadcrumbs
11 from Products.CMFPlone.browser.interfaces import INavigationTabs
12 from Products.CMFPlone.browser.interfaces import ISiteMap
13 from Products.CMFPlone.browser.navtree import SitemapQueryBuilder
14 from Products.CMFPlone.interfaces import IHideFromBreadcrumbs
15 from Products.CMFPlone.interfaces import INavigationSchema
16 from Products.Five import BrowserView
17 from zope.component import getMultiAdapter
18 from zope.component import getUtility
19 from zope.interface import implementer
20 
21 
22 def get_url(item):
23     if not item:
24         return None
25     if hasattr(aq_base(item), 'getURL'):
26         # Looks like a brain
27         return item.getURL()
28     return item.absolute_url()
29 
30 
31 def get_id(item):
32     if not item:
33         return None
34     getId = getattr(item, 'getId')
35     if not utils.safe_callable(getId):
36         # Looks like a brain
37         return getId
38     return getId()
39 
40 
41 def get_view_url(context):
42     registry = getUtility(IRegistry)
43     view_action_types = registry.get(
44         'plone.types_use_view_action_in_listings', [])
45     item_url = get_url(context)
46     name = get_id(context)
47 
48     if getattr(context, 'portal_type', {}) in view_action_types:
49         item_url += '/view'
50         name += '/view'
51 
52     return name, item_url
53 
54 
55 @implementer(ISiteMap)
56 class CatalogSiteMap(BrowserView):
57 
58     def siteMap(self):
59         context = aq_inner(self.context)
60 
61         queryBuilder = SitemapQueryBuilder(context)
62         query = queryBuilder()
63         strategy = getMultiAdapter((context, self), INavtreeStrategy)
64 
65         return buildFolderTree(
66             context, obj=context,
67             query=query, strategy=strategy
68         )
69 
70 
71 @implementer(INavigationTabs)
72 class CatalogNavigationTabs(BrowserView):
73 
74     def _getNavQuery(self):
75                 # check whether we only want actions
76         registry = getUtility(IRegistry)
77         navigation_settings = registry.forInterface(
78             INavigationSchema,
79             prefix="plone",
80             check=False
81         )
82         customQuery = getattr(self.context, 'getCustomNavQuery', False)
83         if customQuery is not None and utils.safe_callable(customQuery):
84             query = customQuery()
85         else:
86             query = {}
87 
88         query['path'] = {
89             'query': getNavigationRoot(self.context),
90             'depth': 1
91         }
92         query['portal_type'] = [t for t in navigation_settings.displayed_types]
93         query['sort_on'] = navigation_settings.sort_tabs_on
94         if navigation_settings.sort_tabs_reversed:
95             query['sort_order'] = 'reverse'
96         else:
97             query['sort_order'] = 'ascending'
98 
99         if navigation_settings.filter_on_workflow:
100             query['review_state'] = navigation_settings.workflow_states_to_show
101 
102         query['is_default_page'] = False
103 
104         if not navigation_settings.nonfolderish_tabs:
105             query['is_folderish'] = True
106 
107         return query
108 
109     def topLevelTabs(self, actions=None, category='portal_tabs'):
110         context = aq_inner(self.context)
111         registry = getUtility(IRegistry)
112         navigation_settings = registry.forInterface(
113             INavigationSchema,
114             prefix="plone",
115             check=False
116         )
117         mtool = getToolByName(context, 'portal_membership')
118         member = mtool.getAuthenticatedMember().id
119         catalog = getToolByName(context, 'portal_catalog')
120 
121         if actions is None:
122             context_state = getMultiAdapter(
123                 (context, self.request),
124                 name=u'plone_context_state'
125             )
126             actions = context_state.actions(category)
127 
128         # Build result dict
129         result = []
130         # first the actions
131         for actionInfo in actions:
132             data = actionInfo.copy()
133             data['name'] = data['title']
134             result.append(data)
135 
136         # check whether we only want actions
137         if not navigation_settings.generate_tabs:
138             return result
139 
140         query = self._getNavQuery()
141 
142         rawresult = catalog.searchResults(query)
143 
144         def _get_url(item):
145             if item.getRemoteUrl and not member == item.Creator:
146                 return (get_id(item), item.getRemoteUrl)
147             return get_view_url(item)
148 
149         # now add the content to results
150         for item in rawresult:
151             if not navigation_settings.show_excluded_items:
152                 if item.exclude_from_nav:
153                     continue
154             cid, item_url = _get_url(item)
155             data = {
156                 'name': utils.pretty_title_or_id(context, item),
157                 'id': item.getId,
158                 'url': item_url,
159                 'description': item.Description,
160                 'review_state': item.review_state
161             }
162             result.append(data)
163 
164         return result
165 
166 
167 @implementer(INavigationBreadcrumbs)
168 class CatalogNavigationBreadcrumbs(BrowserView):
169 
170     def breadcrumbs(self):
171         context = aq_inner(self.context)
172         catalog = getToolByName(context, 'portal_catalog')
173         query = {}
174 
175         # Check to see if the current page is a folder default view, if so
176         # get breadcrumbs from the parent folder
177         if utils.isDefaultPage(context, self.request):
178             currentPath = '/'.join(utils.parent(context).getPhysicalPath())
179         else:
180             currentPath = '/'.join(context.getPhysicalPath())
181         query['path'] = {'query': currentPath, 'navtree': 1, 'depth': 0}
182 
183         rawresult = catalog(**query)
184 
185         # Sort items on path length
186         dec_result = [(len(r.getPath()), r) for r in rawresult]
187         dec_result.sort()
188 
189         rootPath = getNavigationRoot(context)
190 
191         # Build result dict
192         result = []
193         for r_tuple in dec_result:
194             item = r_tuple[1]
195 
196             # Don't include it if it would be above the navigation root
197             itemPath = item.getPath()
198             if rootPath.startswith(itemPath):
199                 continue
200 
201             cid, item_url = get_view_url(item)
202             data = {
203                 'Title': utils.pretty_title_or_id(context, item),
204                 'absolute_url': item_url
205             }
206             result.append(data)
207         return result
208 
209 
210 @implementer(INavigationBreadcrumbs)
211 class PhysicalNavigationBreadcrumbs(BrowserView):
212 
213     def breadcrumbs(self):
214         context = aq_inner(self.context)
215         request = self.request
216         container = utils.parent(context)
217 
218         name, item_url = get_view_url(context)
219 
220         if container is None:
221             return ({
222                 'absolute_url': item_url,
223                 'Title': utils.pretty_title_or_id(context, context),
224             },)
225 
226         view = getMultiAdapter((container, request), name='breadcrumbs_view')
227         base = tuple(view.breadcrumbs())
228 
229         # Some things want to be hidden from the breadcrumbs
230         if IHideFromBreadcrumbs.providedBy(context):
231             return base
232 
233         if base:
234             item_url = '%s/%s' % (base[-1]['absolute_url'], name)
235 
236         rootPath = getNavigationRoot(context)
237         itemPath = '/'.join(context.getPhysicalPath())
238 
239         # don't show default pages in breadcrumbs or pages above the navigation
240         # root
241         if not utils.isDefaultPage(context, request) \
242            and not rootPath.startswith(itemPath):
243             base += ({
244                 'absolute_url': item_url,
245                 'Title': utils.pretty_title_or_id(context, context),
246             },)
247         return base
248 
249 
250 @implementer(INavigationBreadcrumbs)
251 class RootPhysicalNavigationBreadcrumbs(BrowserView):
252 
253     def breadcrumbs(self):
254         # XXX Root never gets included, it's hardcoded as 'Home' in
255         # the template. We will fix and remove the hardcoding and fix
256         # the tests.
257         return ()
258
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/Products/CMFPlone/browser/navigation.py b/Products/CMFPlone/browser/navigation.py
--- a/Products/CMFPlone/browser/navigation.py
+++ b/Products/CMFPlone/browser/navigation.py
@@ -72,7 +72,7 @@
 class CatalogNavigationTabs(BrowserView):
 
     def _getNavQuery(self):
-                # check whether we only want actions
+        # check whether we only want actions
         registry = getUtility(IRegistry)
         navigation_settings = registry.forInterface(
             INavigationSchema,
@@ -101,6 +101,9 @@
 
         query['is_default_page'] = False
 
+        if not navigation_settings.show_excluded_items:
+            query['exclude_from_nav'] = False
+
         if not navigation_settings.nonfolderish_tabs:
             query['is_folderish'] = True
 
@@ -146,11 +149,13 @@
                 return (get_id(item), item.getRemoteUrl)
             return get_view_url(item)
 
+        context_path = '/'.join(context.getPhysicalPath())
+
         # now add the content to results
         for item in rawresult:
-            if not navigation_settings.show_excluded_items:
-                if item.exclude_from_nav:
-                    continue
+            if item.exclude_from_nav and not context_path.startswith(item.getPath()):  # noqa: E501
+                # skip excluded items if they're not in our context path
+                continue
             cid, item_url = _get_url(item)
             data = {
                 'name': utils.pretty_title_or_id(context, item),

{"golden_diff": "diff --git a/Products/CMFPlone/browser/navigation.py b/Products/CMFPlone/browser/navigation.py\n--- a/Products/CMFPlone/browser/navigation.py\n+++ b/Products/CMFPlone/browser/navigation.py\n@@ -72,7 +72,7 @@\n class CatalogNavigationTabs(BrowserView):\n \n     def _getNavQuery(self):\n-                # check whether we only want actions\n+        # check whether we only want actions\n         registry = getUtility(IRegistry)\n         navigation_settings = registry.forInterface(\n             INavigationSchema,\n@@ -101,6 +101,9 @@\n \n         query['is_default_page'] = False\n \n+        if not navigation_settings.show_excluded_items:\n+            query['exclude_from_nav'] = False\n+\n         if not navigation_settings.nonfolderish_tabs:\n             query['is_folderish'] = True\n \n@@ -146,11 +149,13 @@\n                 return (get_id(item), item.getRemoteUrl)\n             return get_view_url(item)\n \n+        context_path = '/'.join(context.getPhysicalPath())\n+\n         # now add the content to results\n         for item in rawresult:\n-            if not navigation_settings.show_excluded_items:\n-                if item.exclude_from_nav:\n-                    continue\n+            if item.exclude_from_nav and not context_path.startswith(item.getPath()):  # noqa: E501\n+                # skip excluded items if they're not in our context path\n+                continue\n             cid, item_url = _get_url(item)\n             data = {\n                 'name': utils.pretty_title_or_id(context, item),\n", "issue": "exclude_from_nav and show_excluded_items are not handled correctly in portal_tabs_view\n### What I did:\r\n\r\nCreate a folder on top level and exclude id from navigation\r\n\r\n### What I expect to happen:\r\n\r\nthe folder should disappear from global navigation **when I'm not inside it's context**\r\n\r\n### What actually happened:\r\n\r\nthe folder is always in the navigation\r\n\r\n### What version of Plone/ Addons I am using:\r\n\r\nplone 5.2rc2\r\n\r\n### REASON:\r\n\r\nI'm fixing a bug found here: https://github.com/plone/plone.app.layout/issues/190\r\nwhich leads to the same result in `portal_tabs_view` here https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/browser/navigation.py#L151-L153\r\n\r\nif `show_excluded_items` is activated (which actually is the default setting) every item is shown regardless of `exclude_from_nav` setting. But what the setting claims is to show the excluded item only if you're inside of it.\r\n\r\nPR is in preparation...\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nfrom Acquisition import aq_base\nfrom Acquisition import aq_inner\nfrom plone.app.layout.navigation.interfaces import INavtreeStrategy\nfrom plone.app.layout.navigation.navtree import buildFolderTree\nfrom plone.app.layout.navigation.root import getNavigationRoot\nfrom plone.registry.interfaces import IRegistry\nfrom Products.CMFCore.utils import getToolByName\nfrom Products.CMFPlone import utils\nfrom Products.CMFPlone.browser.interfaces import INavigationBreadcrumbs\nfrom Products.CMFPlone.browser.interfaces import INavigationTabs\nfrom Products.CMFPlone.browser.interfaces import ISiteMap\nfrom Products.CMFPlone.browser.navtree import SitemapQueryBuilder\nfrom Products.CMFPlone.interfaces import IHideFromBreadcrumbs\nfrom Products.CMFPlone.interfaces import INavigationSchema\nfrom Products.Five import BrowserView\nfrom zope.component import getMultiAdapter\nfrom zope.component import getUtility\nfrom zope.interface import implementer\n\n\ndef get_url(item):\n    if not item:\n        return None\n    if hasattr(aq_base(item), 'getURL'):\n        # Looks like a brain\n        return item.getURL()\n    return item.absolute_url()\n\n\ndef get_id(item):\n    if not item:\n        return None\n    getId = getattr(item, 'getId')\n    if not utils.safe_callable(getId):\n        # Looks like a brain\n        return getId\n    return getId()\n\n\ndef get_view_url(context):\n    registry = getUtility(IRegistry)\n    view_action_types = registry.get(\n        'plone.types_use_view_action_in_listings', [])\n    item_url = get_url(context)\n    name = get_id(context)\n\n    if getattr(context, 'portal_type', {}) in view_action_types:\n        item_url += '/view'\n        name += '/view'\n\n    return name, item_url\n\n\n@implementer(ISiteMap)\nclass CatalogSiteMap(BrowserView):\n\n    def siteMap(self):\n        context = aq_inner(self.context)\n\n        queryBuilder = SitemapQueryBuilder(context)\n        query = queryBuilder()\n        strategy = getMultiAdapter((context, self), INavtreeStrategy)\n\n        return buildFolderTree(\n            context, obj=context,\n            query=query, strategy=strategy\n        )\n\n\n@implementer(INavigationTabs)\nclass CatalogNavigationTabs(BrowserView):\n\n    def _getNavQuery(self):\n                # check whether we only want actions\n        registry = getUtility(IRegistry)\n        navigation_settings = registry.forInterface(\n            INavigationSchema,\n            prefix=\"plone\",\n            check=False\n        )\n        customQuery = getattr(self.context, 'getCustomNavQuery', False)\n        if customQuery is not None and utils.safe_callable(customQuery):\n            query = customQuery()\n        else:\n            query = {}\n\n        query['path'] = {\n            'query': getNavigationRoot(self.context),\n            'depth': 1\n        }\n        query['portal_type'] = [t for t in navigation_settings.displayed_types]\n        query['sort_on'] = navigation_settings.sort_tabs_on\n        if navigation_settings.sort_tabs_reversed:\n            query['sort_order'] = 'reverse'\n        else:\n            query['sort_order'] = 'ascending'\n\n        if navigation_settings.filter_on_workflow:\n            query['review_state'] = navigation_settings.workflow_states_to_show\n\n        query['is_default_page'] = False\n\n        if not navigation_settings.nonfolderish_tabs:\n            query['is_folderish'] = True\n\n        return query\n\n    def topLevelTabs(self, actions=None, category='portal_tabs'):\n        context = aq_inner(self.context)\n        registry = getUtility(IRegistry)\n        navigation_settings = registry.forInterface(\n            INavigationSchema,\n            prefix=\"plone\",\n            check=False\n        )\n        mtool = getToolByName(context, 'portal_membership')\n        member = mtool.getAuthenticatedMember().id\n        catalog = getToolByName(context, 'portal_catalog')\n\n        if actions is None:\n            context_state = getMultiAdapter(\n                (context, self.request),\n                name=u'plone_context_state'\n            )\n            actions = context_state.actions(category)\n\n        # Build result dict\n        result = []\n        # first the actions\n        for actionInfo in actions:\n            data = actionInfo.copy()\n            data['name'] = data['title']\n            result.append(data)\n\n        # check whether we only want actions\n        if not navigation_settings.generate_tabs:\n            return result\n\n        query = self._getNavQuery()\n\n        rawresult = catalog.searchResults(query)\n\n        def _get_url(item):\n            if item.getRemoteUrl and not member == item.Creator:\n                return (get_id(item), item.getRemoteUrl)\n            return get_view_url(item)\n\n        # now add the content to results\n        for item in rawresult:\n            if not navigation_settings.show_excluded_items:\n                if item.exclude_from_nav:\n                    continue\n            cid, item_url = _get_url(item)\n            data = {\n                'name': utils.pretty_title_or_id(context, item),\n                'id': item.getId,\n                'url': item_url,\n                'description': item.Description,\n                'review_state': item.review_state\n            }\n            result.append(data)\n\n        return result\n\n\n@implementer(INavigationBreadcrumbs)\nclass CatalogNavigationBreadcrumbs(BrowserView):\n\n    def breadcrumbs(self):\n        context = aq_inner(self.context)\n        catalog = getToolByName(context, 'portal_catalog')\n        query = {}\n\n        # Check to see if the current page is a folder default view, if so\n        # get breadcrumbs from the parent folder\n        if utils.isDefaultPage(context, self.request):\n            currentPath = '/'.join(utils.parent(context).getPhysicalPath())\n        else:\n            currentPath = '/'.join(context.getPhysicalPath())\n        query['path'] = {'query': currentPath, 'navtree': 1, 'depth': 0}\n\n        rawresult = catalog(**query)\n\n        # Sort items on path length\n        dec_result = [(len(r.getPath()), r) for r in rawresult]\n        dec_result.sort()\n\n        rootPath = getNavigationRoot(context)\n\n        # Build result dict\n        result = []\n        for r_tuple in dec_result:\n            item = r_tuple[1]\n\n            # Don't include it if it would be above the navigation root\n            itemPath = item.getPath()\n            if rootPath.startswith(itemPath):\n                continue\n\n            cid, item_url = get_view_url(item)\n            data = {\n                'Title': utils.pretty_title_or_id(context, item),\n                'absolute_url': item_url\n            }\n            result.append(data)\n        return result\n\n\n@implementer(INavigationBreadcrumbs)\nclass PhysicalNavigationBreadcrumbs(BrowserView):\n\n    def breadcrumbs(self):\n        context = aq_inner(self.context)\n        request = self.request\n        container = utils.parent(context)\n\n        name, item_url = get_view_url(context)\n\n        if container is None:\n            return ({\n                'absolute_url': item_url,\n                'Title': utils.pretty_title_or_id(context, context),\n            },)\n\n        view = getMultiAdapter((container, request), name='breadcrumbs_view')\n        base = tuple(view.breadcrumbs())\n\n        # Some things want to be hidden from the breadcrumbs\n        if IHideFromBreadcrumbs.providedBy(context):\n            return base\n\n        if base:\n            item_url = '%s/%s' % (base[-1]['absolute_url'], name)\n\n        rootPath = getNavigationRoot(context)\n        itemPath = '/'.join(context.getPhysicalPath())\n\n        # don't show default pages in breadcrumbs or pages above the navigation\n        # root\n        if not utils.isDefaultPage(context, request) \\\n           and not rootPath.startswith(itemPath):\n            base += ({\n                'absolute_url': item_url,\n                'Title': utils.pretty_title_or_id(context, context),\n            },)\n        return base\n\n\n@implementer(INavigationBreadcrumbs)\nclass RootPhysicalNavigationBreadcrumbs(BrowserView):\n\n    def breadcrumbs(self):\n        # XXX Root never gets included, it's hardcoded as 'Home' in\n        # the template. We will fix and remove the hardcoding and fix\n        # the tests.\n        return ()\n", "path": "Products/CMFPlone/browser/navigation.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nfrom Acquisition import aq_base\nfrom Acquisition import aq_inner\nfrom plone.app.layout.navigation.interfaces import INavtreeStrategy\nfrom plone.app.layout.navigation.navtree import buildFolderTree\nfrom plone.app.layout.navigation.root import getNavigationRoot\nfrom plone.registry.interfaces import IRegistry\nfrom Products.CMFCore.utils import getToolByName\nfrom Products.CMFPlone import utils\nfrom Products.CMFPlone.browser.interfaces import INavigationBreadcrumbs\nfrom Products.CMFPlone.browser.interfaces import INavigationTabs\nfrom Products.CMFPlone.browser.interfaces import ISiteMap\nfrom Products.CMFPlone.browser.navtree import SitemapQueryBuilder\nfrom Products.CMFPlone.interfaces import IHideFromBreadcrumbs\nfrom Products.CMFPlone.interfaces import INavigationSchema\nfrom Products.Five import BrowserView\nfrom zope.component import getMultiAdapter\nfrom zope.component import getUtility\nfrom zope.interface import implementer\n\n\ndef get_url(item):\n    if not item:\n        return None\n    if hasattr(aq_base(item), 'getURL'):\n        # Looks like a brain\n        return item.getURL()\n    return item.absolute_url()\n\n\ndef get_id(item):\n    if not item:\n        return None\n    getId = getattr(item, 'getId')\n    if not utils.safe_callable(getId):\n        # Looks like a brain\n        return getId\n    return getId()\n\n\ndef get_view_url(context):\n    registry = getUtility(IRegistry)\n    view_action_types = registry.get(\n        'plone.types_use_view_action_in_listings', [])\n    item_url = get_url(context)\n    name = get_id(context)\n\n    if getattr(context, 'portal_type', {}) in view_action_types:\n        item_url += '/view'\n        name += '/view'\n\n    return name, item_url\n\n\n@implementer(ISiteMap)\nclass CatalogSiteMap(BrowserView):\n\n    def siteMap(self):\n        context = aq_inner(self.context)\n\n        queryBuilder = SitemapQueryBuilder(context)\n        query = queryBuilder()\n        strategy = getMultiAdapter((context, self), INavtreeStrategy)\n\n        return buildFolderTree(\n            context, obj=context,\n            query=query, strategy=strategy\n        )\n\n\n@implementer(INavigationTabs)\nclass CatalogNavigationTabs(BrowserView):\n\n    def _getNavQuery(self):\n        # check whether we only want actions\n        registry = getUtility(IRegistry)\n        navigation_settings = registry.forInterface(\n            INavigationSchema,\n            prefix=\"plone\",\n            check=False\n        )\n        customQuery = getattr(self.context, 'getCustomNavQuery', False)\n        if customQuery is not None and utils.safe_callable(customQuery):\n            query = customQuery()\n        else:\n            query = {}\n\n        query['path'] = {\n            'query': getNavigationRoot(self.context),\n            'depth': 1\n        }\n        query['portal_type'] = [t for t in navigation_settings.displayed_types]\n        query['sort_on'] = navigation_settings.sort_tabs_on\n        if navigation_settings.sort_tabs_reversed:\n            query['sort_order'] = 'reverse'\n        else:\n            query['sort_order'] = 'ascending'\n\n        if navigation_settings.filter_on_workflow:\n            query['review_state'] = navigation_settings.workflow_states_to_show\n\n        query['is_default_page'] = False\n\n        if not navigation_settings.show_excluded_items:\n            query['exclude_from_nav'] = False\n\n        if not navigation_settings.nonfolderish_tabs:\n            query['is_folderish'] = True\n\n        return query\n\n    def topLevelTabs(self, actions=None, category='portal_tabs'):\n        context = aq_inner(self.context)\n        registry = getUtility(IRegistry)\n        navigation_settings = registry.forInterface(\n            INavigationSchema,\n            prefix=\"plone\",\n            check=False\n        )\n        mtool = getToolByName(context, 'portal_membership')\n        member = mtool.getAuthenticatedMember().id\n        catalog = getToolByName(context, 'portal_catalog')\n\n        if actions is None:\n            context_state = getMultiAdapter(\n                (context, self.request),\n                name=u'plone_context_state'\n            )\n            actions = context_state.actions(category)\n\n        # Build result dict\n        result = []\n        # first the actions\n        for actionInfo in actions:\n            data = actionInfo.copy()\n            data['name'] = data['title']\n            result.append(data)\n\n        # check whether we only want actions\n        if not navigation_settings.generate_tabs:\n            return result\n\n        query = self._getNavQuery()\n\n        rawresult = catalog.searchResults(query)\n\n        def _get_url(item):\n            if item.getRemoteUrl and not member == item.Creator:\n                return (get_id(item), item.getRemoteUrl)\n            return get_view_url(item)\n\n        context_path = '/'.join(context.getPhysicalPath())\n\n        # now add the content to results\n        for item in rawresult:\n            if item.exclude_from_nav and not context_path.startswith(item.getPath()):  # noqa: E501\n                # skip excluded items if they're not in our context path\n                continue\n            cid, item_url = _get_url(item)\n            data = {\n                'name': utils.pretty_title_or_id(context, item),\n                'id': item.getId,\n                'url': item_url,\n                'description': item.Description,\n                'review_state': item.review_state\n            }\n            result.append(data)\n\n        return result\n\n\n@implementer(INavigationBreadcrumbs)\nclass CatalogNavigationBreadcrumbs(BrowserView):\n\n    def breadcrumbs(self):\n        context = aq_inner(self.context)\n        catalog = getToolByName(context, 'portal_catalog')\n        query = {}\n\n        # Check to see if the current page is a folder default view, if so\n        # get breadcrumbs from the parent folder\n        if utils.isDefaultPage(context, self.request):\n            currentPath = '/'.join(utils.parent(context).getPhysicalPath())\n        else:\n            currentPath = '/'.join(context.getPhysicalPath())\n        query['path'] = {'query': currentPath, 'navtree': 1, 'depth': 0}\n\n        rawresult = catalog(**query)\n\n        # Sort items on path length\n        dec_result = [(len(r.getPath()), r) for r in rawresult]\n        dec_result.sort()\n\n        rootPath = getNavigationRoot(context)\n\n        # Build result dict\n        result = []\n        for r_tuple in dec_result:\n            item = r_tuple[1]\n\n            # Don't include it if it would be above the navigation root\n            itemPath = item.getPath()\n            if rootPath.startswith(itemPath):\n                continue\n\n            cid, item_url = get_view_url(item)\n            data = {\n                'Title': utils.pretty_title_or_id(context, item),\n                'absolute_url': item_url\n            }\n            result.append(data)\n        return result\n\n\n@implementer(INavigationBreadcrumbs)\nclass PhysicalNavigationBreadcrumbs(BrowserView):\n\n    def breadcrumbs(self):\n        context = aq_inner(self.context)\n        request = self.request\n        container = utils.parent(context)\n\n        name, item_url = get_view_url(context)\n\n        if container is None:\n            return ({\n                'absolute_url': item_url,\n                'Title': utils.pretty_title_or_id(context, context),\n            },)\n\n        view = getMultiAdapter((container, request), name='breadcrumbs_view')\n        base = tuple(view.breadcrumbs())\n\n        # Some things want to be hidden from the breadcrumbs\n        if IHideFromBreadcrumbs.providedBy(context):\n            return base\n\n        if base:\n            item_url = '%s/%s' % (base[-1]['absolute_url'], name)\n\n        rootPath = getNavigationRoot(context)\n        itemPath = '/'.join(context.getPhysicalPath())\n\n        # don't show default pages in breadcrumbs or pages above the navigation\n        # root\n        if not utils.isDefaultPage(context, request) \\\n           and not rootPath.startswith(itemPath):\n            base += ({\n                'absolute_url': item_url,\n                'Title': utils.pretty_title_or_id(context, context),\n            },)\n        return base\n\n\n@implementer(INavigationBreadcrumbs)\nclass RootPhysicalNavigationBreadcrumbs(BrowserView):\n\n    def breadcrumbs(self):\n        # XXX Root never gets included, it's hardcoded as 'Home' in\n        # the template. We will fix and remove the hardcoding and fix\n        # the tests.\n        return ()\n", "path": "Products/CMFPlone/browser/navigation.py"}]}