Skip to content

Commit

Permalink
remove fullobjects and get the image from image_field
Browse files Browse the repository at this point in the history
  • Loading branch information
ionlizarazu committed Feb 25, 2022
1 parent 929cbc5 commit fe69427
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
20 changes: 8 additions & 12 deletions src/AdvancedListingBlockTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import { ConditionalLink } from '@plone/volto/components';
import { flattenToAppURL } from '@plone/volto/helpers';
import config from '@plone/volto/registry';

import DefaultImageSVG from '@plone/volto/components/manage/Blocks/Listing/default-image.svg';
import { isInternalURL } from '@plone/volto/helpers/Url/Url';
Expand Down Expand Up @@ -33,16 +32,15 @@ const AdvancedListingBlockTemplate = ({
link = <a href={href}>{linkTitle || href}</a>;
}

const { settings } = config;
const hasImage = imageSide !== null;
const oneColumnElement = ['up', 'down', null].includes(imageSide);
const columnSize = oneColumnElement ? 1 : 2;
const imageGridWidth = oneColumnElement ? 12 : imageWidth ? imageWidth : 2;
const contentGridWidth = oneColumnElement
? 12
: hasImage
? 12 - imageWidth
: 12;
? 12 - imageWidth
: 12;
const intl = useIntl();
moment.locale(intl.locale);
return (
Expand All @@ -54,18 +52,17 @@ const AdvancedListingBlockTemplate = ({
<Grid columns={columnSize}>
{['up', 'left'].includes(imageSide) && (
<Grid.Column width={imageGridWidth}>
{!item[settings.listingPreviewImageField] && (
{!item.image_field && (
<Image
src={DefaultImageSVG}
alt="This content has no image, this is a default placeholder."
size="small"
/>
)}
{item[settings.listingPreviewImageField] && (
{item.image_field && (
<Image
src={flattenToAppURL(
item[settings.listingPreviewImageField].scales.large
.download,
`${item['@id']}/@@images/${item.image_field}/large`,
)}
alt={item.title}
size="small"
Expand All @@ -86,18 +83,17 @@ const AdvancedListingBlockTemplate = ({
</Grid.Column>
{['right', 'down'].includes(imageSide) && (
<Grid.Column width={imageGridWidth}>
{!item[settings.listingPreviewImageField] && (
{!item.image_field && (
<Image
src={DefaultImageSVG}
alt="This content has no image, this is a default placeholder."
size="small"
/>
)}
{item[settings.listingPreviewImageField] && (
{item.image_field && (
<Image
src={flattenToAppURL(
item[settings.listingPreviewImageField].scales.large
.download,
`${item['@id']}/@@images/${item.image_field}/large`,
)}
alt={item.title}
size="small"
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const applyConfig = (config) => {
title: 'Advanced',
template: AdvancedListingBlockTemplate,
schemaEnhancer: advancedSchema,
fullobjects: true,
},
];
return config;
Expand Down

0 comments on commit fe69427

Please sign in to comment.