1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* StaticModule::render_callback() |
4
|
|
|
* |
5
|
|
|
* @package MEE\Modules\StaticModule |
6
|
|
|
* @since ?? |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace MEE\Modules\StaticModule\StaticModuleTrait; |
10
|
|
|
|
11
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
12
|
|
|
die( 'Direct access forbidden.' ); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
// phpcs:disable ET.Sniffs.ValidVariableName.UsedPropertyNotSnakeCase -- WP use snakeCase in \WP_Block_Parser_Block |
16
|
|
|
|
17
|
|
|
use ET\Builder\Packages\Module\Module; |
|
|
|
|
18
|
|
|
use ET\Builder\Framework\Utility\HTMLUtility; |
|
|
|
|
19
|
|
|
use ET\Builder\FrontEnd\BlockParser\BlockParserStore; |
|
|
|
|
20
|
|
|
use ET\Builder\Packages\Module\Options\Element\ElementComponents; |
|
|
|
|
21
|
|
|
use MEE\Modules\StaticModule\StaticModule; |
22
|
|
|
|
23
|
|
|
trait RenderCallbackTrait { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Static module render callback which outputs server side rendered HTML on the Front-End. |
27
|
|
|
* |
28
|
|
|
* @since ?? |
29
|
|
|
* @param array $attrs Block attributes that were saved by VB. |
30
|
|
|
* @param string $content Block content. |
31
|
|
|
* @param WP_Block $block Parsed block object that being rendered. |
|
|
|
|
32
|
|
|
* @param ModuleElements $elements ModuleElements instance. |
|
|
|
|
33
|
|
|
* |
34
|
|
|
* @return string HTML rendered of Static module. |
35
|
|
|
*/ |
36
|
|
|
public static function render_callback( $attrs, $content, $block, $elements ) { |
37
|
|
|
// Image. |
38
|
|
|
$image_src = $attrs['image']['innerContent']['desktop']['value']['src'] ?? ''; |
39
|
|
|
$image_alt = $attrs['image']['innerContent']['desktop']['value']['alt'] ?? ''; |
40
|
|
|
$image = HTMLUtility::render( |
41
|
|
|
[ |
42
|
|
|
'tag' => 'img', |
43
|
|
|
'attributes' => [ |
44
|
|
|
'src' => $image_src, |
45
|
|
|
'alt' => $image_alt, |
46
|
|
|
], |
47
|
|
|
'attributesSanitizers' => [ |
48
|
|
|
'src' => function ( $value ) { |
49
|
|
|
$protocols = array_merge( wp_allowed_protocols(), [ 'data' ] ); // Need to add `data` protocol for default image. |
50
|
|
|
return esc_url( $value, $protocols ); |
51
|
|
|
}, |
52
|
|
|
], |
53
|
|
|
] |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
// Image container. |
57
|
|
|
$image_container = HTMLUtility::render( |
58
|
|
|
[ |
59
|
|
|
'tag' => 'div', |
60
|
|
|
'attributes' => [ |
61
|
|
|
'class' => 'example_static_module__image', |
62
|
|
|
], |
63
|
|
|
'childrenSanitizer' => 'et_core_esc_previously', |
64
|
|
|
'children' => $image, |
65
|
|
|
] |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
// Title. |
69
|
|
|
$title = $elements->render( |
70
|
|
|
[ |
71
|
|
|
'attrName' => 'title', |
72
|
|
|
] |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
// Content. |
76
|
|
|
$content = $elements->render( |
77
|
|
|
[ |
78
|
|
|
'attrName' => 'content', |
79
|
|
|
] |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
// Content container. |
83
|
|
|
$content_container = HTMLUtility::render( |
84
|
|
|
[ |
85
|
|
|
'tag' => 'div', |
86
|
|
|
'attributes' => [ |
87
|
|
|
'class' => 'example_static_module__content-container', |
88
|
|
|
], |
89
|
|
|
'childrenSanitizer' => 'et_core_esc_previously', |
90
|
|
|
'children' => $title . $content, |
91
|
|
|
] |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$parent = BlockParserStore::get_parent( $block->parsed_block['id'], $block->parsed_block['storeInstance'] ); |
95
|
|
|
$parent_attrs = $parent->attrs ?? []; |
96
|
|
|
|
97
|
|
|
return Module::render( |
98
|
|
|
[ |
99
|
|
|
// FE only. |
100
|
|
|
'orderIndex' => $block->parsed_block['orderIndex'], |
101
|
|
|
'storeInstance' => $block->parsed_block['storeInstance'], |
102
|
|
|
|
103
|
|
|
// VB equivalent. |
104
|
|
|
'attrs' => $attrs, |
105
|
|
|
'elements' => $elements, |
106
|
|
|
'id' => $block->parsed_block['id'], |
107
|
|
|
'name' => $block->block_type->name, |
108
|
|
|
'moduleCategory' => $block->block_type->category, |
109
|
|
|
'classnamesFunction' => [ StaticModule::class, 'module_classnames' ], |
110
|
|
|
'stylesComponent' => [ StaticModule::class, 'module_styles' ], |
111
|
|
|
'scriptDataComponent' => [ StaticModule::class, 'module_script_data' ], |
112
|
|
|
'parentAttrs' => $parent_attrs, |
113
|
|
|
'parentId' => $parent->id ?? '', |
114
|
|
|
'parentName' => $parent->blockName ?? '', |
115
|
|
|
'children' => [ |
116
|
|
|
ElementComponents::component( |
117
|
|
|
[ |
118
|
|
|
'attrs' => $attrs['module']['decoration'] ?? [], |
119
|
|
|
'id' => $block->parsed_block['id'], |
120
|
|
|
|
121
|
|
|
// FE only. |
122
|
|
|
'orderIndex' => $block->parsed_block['orderIndex'], |
123
|
|
|
'storeInstance' => $block->parsed_block['storeInstance'], |
124
|
|
|
] |
125
|
|
|
), |
126
|
|
|
HTMLUtility::render( |
127
|
|
|
[ |
128
|
|
|
'tag' => 'div', |
129
|
|
|
'attributes' => [ |
130
|
|
|
'class' => 'example_static_module__inner', |
131
|
|
|
], |
132
|
|
|
'childrenSanitizer' => 'et_core_esc_previously', |
133
|
|
|
'children' => $image_container . $content_container, |
134
|
|
|
] |
135
|
|
|
), |
136
|
|
|
], |
137
|
|
|
] |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths