Added custom illustration adapter for navigation links
authorThierry Florac <thierry.florac@onf.fr>
Thu, 12 Jul 2018 11:48:49 +0200
changeset 89 62c88c2ad06a
parent 88 f3beaff7c4fe
child 90 fcca5c883a43
Added custom illustration adapter for navigation links
src/pyams_default_theme/features/menu/__init__.py
--- a/src/pyams_default_theme/features/menu/__init__.py	Thu Jul 12 11:48:23 2018 +0200
+++ b/src/pyams_default_theme/features/menu/__init__.py	Thu Jul 12 11:48:49 2018 +0200
@@ -16,5 +16,23 @@
 # import standard library
 
 # import interfaces
+from pyams_content.component.illustration import IBasicIllustration
+from pyams_content.component.links.interfaces import IBaseLink, IInternalLink
+from pyams_default_theme.interfaces import IContentNavigationIllustration
+from pyams_skin.layer import IPyAMSUserLayer
 
 # import packages
+from pyams_utils.adapter import adapter_config
+
+
+@adapter_config(context=(IBaseLink, IPyAMSUserLayer), provides=IContentNavigationIllustration)
+def base_link_navigation_illustration_adapter(context, request):
+    """Base link navigation illustration adapter"""
+    illustration = IBasicIllustration(context, None)
+    if not (illustration and illustration.has_data()):
+        if IInternalLink.providedBy(context):
+            target = context.get_target()
+            if target is not None:
+                illustration = request.registry.queryMultiAdapter((target, request),
+                                                                  IContentNavigationIllustration)
+    return illustration