Use menu header interface adapter to set menu header
authorThierry Florac <thierry.florac@onf.fr>
Wed, 07 Oct 2015 17:59:52 +0200
changeset 90 2c75cd01d282
parent 89 5eee812ae968
child 91 e2d4f0f88188
Use menu header interface adapter to set menu header
src/pyams_skin/viewlet/menu/__init__.py
--- a/src/pyams_skin/viewlet/menu/__init__.py	Wed Oct 07 17:58:51 2015 +0200
+++ b/src/pyams_skin/viewlet/menu/__init__.py	Wed Oct 07 17:59:52 2015 +0200
@@ -15,7 +15,7 @@
 # import standard library
 
 # import interfaces
-from pyams_skin.interfaces.viewlet import IMainMenusViewletManager, IMenu, IMenuItem
+from pyams_skin.interfaces.viewlet import IMainMenusViewletManager, IMenu, IMenuItem, IMenuHeader
 from pyams_skin.layer import IPyAMSLayer
 
 # import packages
@@ -45,12 +45,25 @@
 class Menu(TemplateBasedViewletManager, WeightOrderedViewletManager, Viewlet):
     """Menu header"""
 
-    header = FieldProperty(IMenu['header'])
+    _header = FieldProperty(IMenu['header'])
 
     def __init__(self, context, request, view, manager=None):
         WeightOrderedViewletManager.__init__(self, context, request, view)
         Viewlet.__init__(self, context, request, view, manager)
 
+    @property
+    def header(self):
+        registry = self.request.registry
+        header = registry.queryMultiAdapter((self.context, self.request, self.__parent__, self), IMenuHeader)
+        if header is None:
+            header = registry.queryMultiAdapter((self.context, self.request, self), IMenuHeader)
+        if header is None:
+            header = registry.queryMultiAdapter((self.context, self), IMenuHeader)
+        if header is not None:
+            return header.header
+        else:
+            return self._header
+
     def update(self):
         WeightOrderedViewletManager.update(self)