Generics
1 year ago
Props
1 month ago
BlockStyleRender.php
1 year ago
DynamicStyles.php
1 year ago
GlobalStyleRender.php
1 year ago
MainAttribute.php
4 years ago
ParserUtils.php
1 year ago
StyleManager.php
2 years ago
StyleParser.php
1 year ago
StyleRender.php
1 year ago
Utils.php
1 year ago
BlockStyleRender.php
69 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Core\StyleManager; |
| 4 | |
| 5 | use Kubio\Config; |
| 6 | use Kubio\Core\LodashBasic; |
| 7 | |
| 8 | class BlockStyleRender extends StyleRender { |
| 9 | protected $block; |
| 10 | private $styleRef; |
| 11 | |
| 12 | |
| 13 | private static $rendererRefs = array(); |
| 14 | |
| 15 | protected $parentBlock = null; |
| 16 | protected $parentStyleRenderer = null; |
| 17 | |
| 18 | public static function normalizeBlockData( $mainAttr, $blockType ) { |
| 19 | $supports = $blockType->supports; |
| 20 | $styledElementsByName = LodashBasic::get( $supports, array( Config::$mainAttributeKey, Config::$elementsKey ), array() ); |
| 21 | $styledElementsEnum = LodashBasic::get( $supports, array( Config::$mainAttributeKey, Config::$elementsEnum ), array() ); |
| 22 | |
| 23 | return self::normalizeData( $mainAttr, $styledElementsByName, $styledElementsEnum ); |
| 24 | } |
| 25 | |
| 26 | |
| 27 | public function setFlags() { |
| 28 | } |
| 29 | |
| 30 | |
| 31 | public function __construct( $block, $parent_block = null ) { |
| 32 | $this->block = $block; |
| 33 | $this->parentBlock = $parent_block; |
| 34 | $this->parentStyleRenderer = $parent_block ? new BlockStyleRender( $parent_block ) : null; |
| 35 | $mainAttr = $block->getMergedMainAttribute(); |
| 36 | $this->styleRef = LodashBasic::get( $mainAttr, 'styleRef', null ); |
| 37 | |
| 38 | // check if the same style was already rendered and skip new renders |
| 39 | if ( $this->styleRef && in_array( $this->styleRef, BlockStyleRender::$rendererRefs, true ) ) { |
| 40 | $this->skipSharedStyleRender = true; |
| 41 | } |
| 42 | |
| 43 | BlockStyleRender::$rendererRefs[] = $this->styleRef; |
| 44 | |
| 45 | $normalized = self::normalizeBlockData( array_merge( $mainAttr, array( 'id' => $this->block->localId() ) ), $block->block_type ); |
| 46 | $this->model = (object) LodashBasic::get( $normalized, 'model', array() ); |
| 47 | |
| 48 | $prefixParents = array(); |
| 49 | $useParentPrefix = $this->block->getBlockSupport( 'useParentPrefix' ); |
| 50 | if ( $this->parentBlock ) { |
| 51 | $prefixParents[] = '.' . $this->parentStyleRenderer->componentInstanceClass( $this->parentBlock->getWrapperElementName(), 'shared' ); |
| 52 | } |
| 53 | |
| 54 | parent::__construct( |
| 55 | array( |
| 56 | 'styledElementsByName' => LodashBasic::get( $normalized, 'styledElementsByName', array() ), |
| 57 | 'styledElementsEnum' => LodashBasic::get( $normalized, 'styledElementsEnum', array() ), |
| 58 | 'wrapperElement' => $block->getWrapperElementName(), |
| 59 | 'prefixParents' => $prefixParents, |
| 60 | 'useParentPrefix' => $useParentPrefix, |
| 61 | ) |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | public function export( $dynamicStyle = null ) { |
| 66 | return parent::export( $dynamicStyle ); |
| 67 | } |
| 68 | } |
| 69 |