Skip to content

Commit

Permalink
Merge pull request #54 from wtey-webmd/feature/AP-703
Browse files Browse the repository at this point in the history
feat(AP-703): add displayCopyright to image attrs
  • Loading branch information
nedSaf authored Jun 5, 2024
2 parents 09bd6a8 + 970a766 commit 4036dc0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/image/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
Disabled,
Button,
ResponsiveWrapper,
ToggleControl,
} = wp.components;
const { useSelect } = wp.data;

Expand Down Expand Up @@ -179,6 +180,10 @@ function getCopyright(image) {
return image && image.media_fields ? get(image, 'media_fields.field_copyright.value.value') : '';
}

function getDisplayCopyright(image) {
return get(image, 'media_fields.field_copyright_enable.value.value') === 'on' ? true : false;
}

function getCrop(image, cropName) {
if (!image) return;
const key = Object.keys(image.media_details.crops).find((key) => {
Expand Down Expand Up @@ -298,6 +303,7 @@ const withSrcAttribute = createHigherOrderComponent((BlockEdit) => {
? props.attributes.alt
: get(image, 'media_fields.field_media_image.value.alt'),
copyright: get(image, 'media_fields.field_copyright.value.value'),
displayCopyright: getDisplayCopyright(image),
size: !props.attributes.size
? sizeControlOptions.find((o) => o.default).value
: props.attributes.size,
Expand Down Expand Up @@ -472,6 +478,12 @@ const withSrcAttribute = createHigherOrderComponent((BlockEdit) => {
help={__('Could be changed in gallery')}
value={getCopyright(image)}
/>

<ToggleControl
label={__('Display copyright')}
help={__('Could be changed in gallery')}
checked={getDisplayCopyright(image)}
/>
</Disabled>
</PanelBody>
</InspectorControls>
Expand Down
15 changes: 12 additions & 3 deletions src/image_gallery/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { createHigherOrderComponent } = wp.compose;
const { InspectorControls } = wp.blockEditor;
const { Fragment } = wp.element;
const { addFilter } = wp.hooks;
const { PanelBody, TextControl, Disabled } = wp.components;
const { PanelBody, TextControl, Disabled, ToggleControl } = wp.components;
const { useSelect } = wp.data;
const { __ } = wp.i18n;

Expand Down Expand Up @@ -109,6 +109,11 @@ const withCustomFeatures = createHigherOrderComponent((BlockEdit) => {
'',
);

storage.displayCopyright =
get(images, '[' + i + '].media_fields.field_copyright_enable.value.value', '') === 'on'
? true
: false;

const mediaDetails = get(images, '[' + i + '].media_details');

if (mediaDetails) {
Expand Down Expand Up @@ -146,13 +151,17 @@ const withCustomFeatures = createHigherOrderComponent((BlockEdit) => {
<InspectorControls>
<PanelBody title={__('Copyright Info')} initialOpen={true}>
{props.attributes.images.map((item, index) => (
<Disabled>
<Disabled key={index}>
<TextControl
key={index}
label={__('Copyright id' + item ? item.id : '')}
help={__('can be changed in media library')}
value={item.copyright}
/>
<ToggleControl
label={__('Display Copyright id' + item ? item.id : '')}
help={__('can be changed in media library')}
checked={item.displayCopyright}
/>
</Disabled>
))}
</PanelBody>
Expand Down

0 comments on commit 4036dc0

Please sign in to comment.