| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Modules\Templating\BlockTemplates; |
| 4 |
|
| 5 |
/** |
| 6 |
* ProductCategoryTemplate class. |
| 7 |
* |
| 8 |
*/ |
| 9 |
class ProductModalTemplate |
| 10 |
{ |
| 11 |
|
| 12 |
/** |
| 13 |
* The slug of the template. |
| 14 |
* |
| 15 |
* @var string |
| 16 |
*/ |
| 17 |
const SLUG = 'fct-single-product-modal'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Initialization method. |
| 21 |
*/ |
| 22 |
public function init() |
| 23 |
{ |
| 24 |
register_block_template('fluent-cart//fct-single-product-modal', [ |
| 25 |
'title' => $this->getTitle(), |
| 26 |
'description' => $this->getDescription(), |
| 27 |
'content' => $this->getDefaultTemplate(), |
| 28 |
]); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Returns the title of the template. |
| 33 |
* |
| 34 |
* @return string |
| 35 |
*/ |
| 36 |
public function getTitle() |
| 37 |
{ |
| 38 |
return _x('Single Product Modal', 'Template name', 'fluent-cart'); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Returns the description of the template. |
| 43 |
* |
| 44 |
* @return string |
| 45 |
*/ |
| 46 |
public function getDescription() |
| 47 |
{ |
| 48 |
return __('Template for Single Product Modal.', 'fluent-cart'); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
public function getDefaultTemplate() |
| 53 |
{ |
| 54 |
ob_start(); |
| 55 |
?> |
| 56 |
<!-- wp:group {"tagName":"main","templateLock":"contentOnly","lock":{"move":false,"remove":false},"className":"alignfull is-style-default","layout":{"type":"default"}} --> |
| 57 |
<main class="wp-block-group alignfull is-style-default"> |
| 58 |
<!-- wp:group {"lock":{"move":false,"remove":false},"align":"wide","layout":{"type":"default"}} --> |
| 59 |
<div class="wp-block-group alignwide"><!-- wp:shortcode -->[fluent_cart_product_header] |
| 60 |
<!-- /wp:shortcode --></div> |
| 61 |
<!-- /wp:group --></main> |
| 62 |
<!-- /wp:group --> |
| 63 |
<?php |
| 64 |
return ob_get_clean(); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Render the template with custom content if modified by user |
| 69 |
* |
| 70 |
* @return string |
| 71 |
*/ |
| 72 |
public function render() |
| 73 |
{ |
| 74 |
$templates = get_block_templates(['slug__in' => [self::SLUG]]); |
| 75 |
if (!empty($templates) && isset($templates[0]->content)) { |
| 76 |
$content = $templates[0]->content; |
| 77 |
return do_shortcode(do_blocks($content)); |
| 78 |
} |
| 79 |
|
| 80 |
return do_shortcode(do_blocks($this->getDefaultTemplate())); |
| 81 |
} |
| 82 |
} |
| 83 |
|