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