| 1 |
/** |
| 2 |
* Product Block specific functions for Gutenberg. |
| 3 |
* |
| 4 |
* @since 1.9.6.5 |
| 5 |
* |
| 6 |
* @package ConvertKit |
| 7 |
* @author ConvertKit |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* Custom callback function to render the ConvertKit Product Block preview in the Gutenberg Editor. |
| 12 |
* |
| 13 |
* @since 1.9.8.5 |
| 14 |
*/ |
| 15 |
function convertKitGutenbergProductBlockRenderPreview( block, props ) { |
| 16 |
|
| 17 |
// If no API Key has been defined in the Plugin, return a prompt to tell the editor |
| 18 |
// what to do. |
| 19 |
if ( ! block.has_access_token ) { |
| 20 |
return convertKitGutenbergDisplayBlockNoticeWithLink( |
| 21 |
block.name, |
| 22 |
block.no_access_token.notice, |
| 23 |
block.no_access_token.link, |
| 24 |
block.no_access_token.link_text |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
// If no Products exist in ConvertKit, return a prompt to tell the editor |
| 29 |
// what to do. |
| 30 |
if ( ! block.has_resources ) { |
| 31 |
return convertKitGutenbergDisplayBlockNoticeWithLink( |
| 32 |
block.name, |
| 33 |
block.no_resources.notice, |
| 34 |
block.no_resources.link, |
| 35 |
block.no_resources.link_text |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
// If no Product has been selected for display, return a prompt to tell the editor |
| 40 |
// what to do. |
| 41 |
if ( props.attributes.product === '' ) { |
| 42 |
return convertKitGutenbergDisplayBlockNotice( block.name, block.gutenberg_help_description ); |
| 43 |
} |
| 44 |
|
| 45 |
// A Product is specified. |
| 46 |
// Use the block's PHP's render() function by calling the ServerSideRender component. |
| 47 |
return wp.element.createElement( |
| 48 |
wp.serverSideRender, |
| 49 |
{ |
| 50 |
block: 'convertkit/' + block.name, |
| 51 |
attributes: props.attributes, |
| 52 |
|
| 53 |
// This is only output in the Gutenberg editor, so must be slightly different from the inner class name used to |
| 54 |
// apply styles with i.e. convertkit-block.name. |
| 55 |
className: 'convertkit-ssr-' + block.name, |
| 56 |
} |
| 57 |
); |
| 58 |
|
| 59 |
} |
| 60 |
|