PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.8.0
GenerateBlocks v1.8.0
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / blocks / image / save.js
generateblocks / src / blocks / image Last commit date
components 2 years ago css 2 years ago block.json 2 years ago edit.js 2 years ago editor.scss 3 years ago index.js 2 years ago save.js 4 years ago transforms.js 4 years ago
save.js
82 lines
1 import classnames from 'classnames';
2 import Element from '../../components/element';
3 import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';
4 import { applyFilters } from '@wordpress/hooks';
5 import { removeEmpty } from '../query-loop/components/utils';
6 import AnchorTag from './components/AnchorTag';
7
8 export default ( { attributes } ) => {
9 const {
10 uniqueId,
11 mediaUrl,
12 anchor,
13 alt,
14 title,
15 href,
16 openInNewWindow,
17 relNoFollow,
18 relSponsored,
19 useDynamicData,
20 dynamicContentType,
21 className,
22 align,
23 } = attributes;
24
25 if ( useDynamicData && dynamicContentType ) {
26 return <InnerBlocks.Content />;
27 }
28
29 if ( ! mediaUrl ) {
30 return null;
31 }
32
33 const figureAttributes = useBlockProps.save( {
34 className: classnames( {
35 'gb-block-image': true,
36 [ `gb-block-image-${ uniqueId }` ]: true,
37 } ),
38 } );
39
40 // We don't want our className appearing in the figure.
41 if ( figureAttributes?.className.includes( className ) ) {
42 figureAttributes.className = figureAttributes.className.replace( className, '' ).trim();
43 }
44
45 const htmlAttributes = applyFilters(
46 'generateblocks.frontend.htmlAttributes',
47 {
48 className: classnames( {
49 'gb-image': true,
50 [ `gb-image-${ uniqueId }` ]: true,
51 [ `${ className }` ]: undefined !== className,
52 [ `align${ align }` ]: '' !== align,
53 } ),
54 id: anchor ? anchor : null,
55 src: mediaUrl,
56 alt,
57 title,
58 },
59 'generateblocks/image',
60 attributes
61 );
62
63 const imageAttributes = removeEmpty( htmlAttributes );
64
65 const anchorAttributes = {
66 href,
67 openInNewWindow,
68 relNoFollow,
69 relSponsored,
70 };
71
72 return (
73 <Element tagName="figure" htmlAttrs={ figureAttributes }>
74 <AnchorTag { ...anchorAttributes }>
75 <Element tagName="img" htmlAttrs={ imageAttributes } />
76 </AnchorTag>
77
78 <InnerBlocks.Content />
79 </Element>
80 );
81 };
82