--- a/src/pyams_content/shared/imagemap/paragraph.py Fri Nov 10 12:03:07 2017 +0100
+++ b/src/pyams_content/shared/imagemap/paragraph.py Fri Nov 10 12:03:41 2017 +0100
@@ -17,12 +17,17 @@
# import interfaces
from pyams_content.component.paragraph.interfaces import IParagraphFactory
+from pyams_content.features.checker.interfaces import IContentChecker, ERROR_VALUE, MISSING_VALUE, MISSING_LANG_VALUE
from pyams_content.shared.imagemap.interfaces import IImageMapParagraph
+from pyams_i18n.interfaces import II18nManager, INegotiator, II18n
+from pyams_workflow.interfaces import IWorkflow
# import packages
-from pyams_content.component.paragraph import BaseParagraph
+from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker
from pyams_sequence.utility import get_reference_target
-from pyams_utils.registry import utility_config
+from pyams_utils.adapter import adapter_config
+from pyams_utils.registry import utility_config, get_utility
+from pyams_utils.traversing import get_parent
from zope.interface import implementer
from zope.schema.fieldproperty import FieldProperty
@@ -48,3 +53,34 @@
name = _("Image map")
content_type = ImageMapParagraph
+
+
+@adapter_config(context=IImageMapParagraph, provides=IContentChecker)
+class ImageMapParagraphContentChecker(BaseParagraphContentChecker):
+ """ImageMap paragraph content checker"""
+
+ def inner_check(self, request):
+ output = []
+ translate = request.localizer.translate
+ manager = get_parent(self.context, II18nManager)
+ if manager is not None:
+ langs = manager.get_languages()
+ else:
+ negotiator = get_utility(INegotiator)
+ langs = (negotiator.server_language, )
+ i18n = II18n(self.context)
+ for lang in langs:
+ value = i18n.get_attribute('title', lang, request)
+ if not value:
+ field_title = translate(IImageMapParagraph['title'].title)
+ if len(langs) == 1:
+ output.append(translate(MISSING_VALUE).format(field=field_title))
+ else:
+ output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang))
+ target = self.context.get_target()
+ if target is not None:
+ workflow = IWorkflow(target, None)
+ if workflow is not None:
+ output.append(translate(ERROR_VALUE).format(field=translate(IImageMapParagraph['reference'].title),
+ message=translate(_("target is not published"))))
+ return output