Skip to content

Commit

Permalink
Merge pull request #148 from plone/fiximagescalesserializer
Browse files Browse the repository at this point in the history
Fix for parent summary serializer when the parent has a  but it's empty
  • Loading branch information
davisagli authored May 1, 2024
2 parents 1c73473 + 727d514 commit dffae07
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
3 changes: 3 additions & 0 deletions news/148.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix for preview_image_link image_scales adapter when the field is empty.
Swap condition for `image_field` indexer, `preview_image_link` first, then the default `preview_image`
[sneridagh]
29 changes: 16 additions & 13 deletions src/plone/volto/behaviors/preview_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ def __init__(self, field, context, request):

def __call__(self):
value = self.field.get(self.context)
linked_image = value.to_object
primary_field = IPrimaryFieldInfo(linked_image).field
serializer = queryMultiAdapter(
(primary_field, linked_image, self.request), IImageScalesFieldAdapter
)
if serializer is not None:
values = serializer()
if values:
portal_url = api.portal.get().absolute_url()
base_path = linked_image.absolute_url().replace(portal_url, "")
for value in values:
value["base_path"] = base_path
return values
if value:
linked_image = value.to_object
primary_field = IPrimaryFieldInfo(linked_image).field
serializer = queryMultiAdapter(
(primary_field, linked_image, self.request), IImageScalesFieldAdapter
)
if serializer is not None:
values = serializer()
if values:
portal_url = api.portal.get().absolute_url()
base_path = linked_image.absolute_url().replace(portal_url, "")
for value in values:
value["base_path"] = base_path
return values

return []
6 changes: 3 additions & 3 deletions src/plone/volto/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def image_field_indexer(obj):
base_obj = aq_base(obj)

image_field = ""
if getattr(base_obj, "preview_image", False):
image_field = "preview_image"
elif (
if (
getattr(base_obj, "preview_image_link", False)
and not base_obj.preview_image_link.isBroken()
):
image_field = "preview_image_link"
elif getattr(base_obj, "preview_image", False):
image_field = "preview_image"
elif getattr(base_obj, "image", False):
image_field = "image"
return image_field
Expand Down

0 comments on commit dffae07

Please sign in to comment.