| @@ -1,0 +1,63 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Payment Buttons block render implementation. | |
| 4 | + * | |
| 5 | + * Loaded lazily from payment-buttons.php only when the block is rendered, to | |
| 6 | + * keep the render body out of the eager front-end PHP/opcache footprint. | |
| 7 | + * | |
| 8 | + * @package automattic/jetpack | |
| 9 | + */ | |
| 10 | + | |
| 11 | +namespace Automattic\Jetpack\Extensions\PaymentButtons; | |
| 12 | + | |
| 13 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 14 | + exit( 0 ); | |
| 15 | +} | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * Render implementation. | |
| 19 | + * | |
| 20 | + * @param array $attributes Array containing the block attributes. | |
| 21 | + * @param string $content String containing the block content. | |
| 22 | + * | |
| 23 | + * @return string | |
| 24 | + */ | |
| 25 | +function render_block_implementation( $attributes, $content ) { | |
| 26 | + \Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); | |
| 27 | + | |
| 28 | + return $content; | |
| 29 | +} | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * Render email implementation. | |
| 33 | + * | |
| 34 | + * @param string $block_content The block content. | |
| 35 | + * @param array $parsed_block The parsed block data. | |
| 36 | + * @param object $rendering_context The email rendering context. | |
| 37 | + * | |
| 38 | + * @return string | |
| 39 | + */ | |
| 40 | +function render_block_email_implementation( $block_content, array $parsed_block, $rendering_context ) { | |
| 41 | + if ( ! class_exists( '\Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer\Layout\Flex_Layout_Renderer' ) ) { | |
| 42 | + return ''; | |
| 43 | + } | |
| 44 | + | |
| 45 | + /* | |
| 46 | + * Ignore font size set on the buttons block. | |
| 47 | + * We rely on TypographyPreprocessor to set the font size on the buttons. | |
| 48 | + * Rendering font size on the wrapper causes unwanted whitespace below the buttons. | |
| 49 | + */ | |
| 50 | + if ( isset( $parsed_block['attrs']['style']['typography']['fontSize'] ) ) { | |
| 51 | + unset( $parsed_block['attrs']['style']['typography']['fontSize'] ); | |
| 52 | + } | |
| 53 | + | |
| 54 | + // We are checking for the class existence above, so we know it exists. | |
| 55 | + $flex_layout_renderer = new \Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer\Layout\Flex_Layout_Renderer(); | |
| 56 | + | |
| 57 | + if ( ! method_exists( $flex_layout_renderer, 'render_inner_blocks_in_layout' ) ) { | |
| 58 | + return ''; | |
| 59 | + } | |
| 60 | + | |
| 61 | + // We are checking for the method existence above, so we know it exists. | |
| 62 | + return $flex_layout_renderer->render_inner_blocks_in_layout( $parsed_block, $rendering_context ); | |
| 63 | +} | |