PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 1.6.4
Kubio AI Page Builder v1.6.4
2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / src / Core / Blocks / BlockElement.php
kubio / lib / src / Core / Blocks Last commit date
Query 3 years ago BlockBase.php 3 years ago BlockContainerBase.php 4 years ago BlockElement.php 4 years ago BlockStyle.php 4 years ago DataHelper.php 4 years ago TemplatePartBlockBase.php 4 years ago
BlockElement.php
115 lines
1 <?php
2
3 namespace Kubio\Core\Blocks;
4
5 use Kubio\Core\Element;
6 use Kubio\Core\LodashBasic;
7 use Kubio\Core\Registry;
8 use function str_replace;
9
10 class BlockElement extends Element {
11
12 public $config;
13 public $name;
14
15 function __construct( $type, $props = array(), $children = array(), $block = null ) {
16 if ( isset( $props['name'] ) ) {
17 $this->name = $props['name'];
18 unset( $props['name'] );
19 }
20 parent::__construct( $type, $props, $children, $block );
21 }
22
23 function __toString() {
24 $props = $this->getFinalProps();
25 if ( ! $this->shouldRender ) {
26 return '';
27 }
28
29 return Registry::getInstance()->createElement( $this->tagName( $props ), $props, $this->children ) . '';
30 }
31
32 function getFinalProps() {
33 return $this->mergeProps(
34 parent::getProps(),
35 array( 'className' => $this->getClassName() ),
36 $this->mappedProps()
37 );
38 }
39
40 function getClassName() {
41 $classes = parent::getClassName();
42
43 return $this->getClasses( $classes );
44 }
45
46 function getClasses( $extraClasses = array() ) {
47
48 $classes = LodashBasic::concat(
49 array(
50 'position-relative',
51
52 $this->getBemClass( $this->block->name() ),
53 ),
54 $extraClasses
55 );
56 $blockElement = $this->block->elements[0];
57 $disableStyleClasses = property_exists( $blockElement, 'disableStyleClasses' ) && $blockElement->disableStyleClasses;
58
59 if ( ! $disableStyleClasses ) {
60 $classes = LodashBasic::concat(
61 $classes,
62 array(
63 $this->getSharedClass( $this->block->getMainAttributeProp( 'styleRef' ) ),
64 $this->getLocalClasses( $this->block->localId() ),
65 )
66 );
67 }
68
69 return $classes;
70 }
71
72 function getBemClass( $blockName ) {
73 return 'wp-block-' . str_replace( '/', '-', $blockName ) . '__' . $this->name;
74 }
75
76 function getSharedClass( $styleRef ) {
77 $style_prefix = apply_filters( 'kubio/element-style-class-prefix', 'style-' );
78
79 return $style_prefix . $styleRef . '-' . $this->name;
80 }
81
82 function getLocalClasses( $localId = null ) {
83 $style_prefix = apply_filters( 'kubio/element-style-class-prefix', 'style-' );
84 $style_prefix = "{$style_prefix}local-";
85 return $localId ? $style_prefix . $localId . '-' . $this->name : false;
86 }
87
88 function mappedProps() {
89 $mappedProps = array();
90 if ( $this->block ) {
91 $props = $this->getConfig( 'props', array() );
92 $mappedProps = array( 'className' => $this->getConfig( 'classes', array() ) );
93 $mapped = LodashBasic::get(
94 apply_filters( 'kubio/blocks/element_props_map', $this->block->mapPropsToElementsWithDefaults(), $this->block ),
95 $this->name
96 );
97 $mappedProps = $this->mergeProps( $props, $mappedProps, $mapped );
98 }
99
100 return $mappedProps;
101 }
102
103 function getConfig( $path, $defaultValue = null ) {
104 return $this->block->getStyledElementConfig( $this->name, $path, $defaultValue );
105 }
106
107 function tagName( $props = null ) {
108 if ( $props && isset( $props['tag'] ) ) {
109 return $props['tag'];
110 }
111
112 return $this->getConfig( 'tag', $this->type );
113 }
114 }
115