QueryLoopItemBase.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Core\Blocks\Query; |
| 4 | |
| 5 | use Kubio\Core\Blocks\BlockContainerBase; |
| 6 | use Kubio\Core\Layout\LayoutHelper; |
| 7 | use Kubio\Core\LodashBasic; |
| 8 | use Kubio\Core\Registry; |
| 9 | use Kubio\Core\StyleManager\DynamicStyles; |
| 10 | |
| 11 | abstract class QueryLoopItemBase extends BlockContainerBase { |
| 12 | |
| 13 | const CONTAINER = 'container'; |
| 14 | const INNER = 'inner'; |
| 15 | const ALIGN = 'align'; |
| 16 | const VSPACE = 'v-space'; |
| 17 | |
| 18 | public function mapDynamicStyleToElements() { |
| 19 | $dynamic_styles = array(); |
| 20 | $space_by_media = $this->getPropByMedia( |
| 21 | 'layout.vSpace', |
| 22 | array() |
| 23 | ); |
| 24 | |
| 25 | $dynamic_styles[ self::VSPACE ] = DynamicStyles::vSpace( $space_by_media ); |
| 26 | |
| 27 | return $dynamic_styles; |
| 28 | } |
| 29 | |
| 30 | public function mapPropsToElements() { |
| 31 | $row_block = Registry::getInstance()->getLastBlockOfName( $this->loopBlockName() ); |
| 32 | |
| 33 | $column_width_by_media = $this->getStyleByMedia( |
| 34 | 'columnWidth', |
| 35 | array(), |
| 36 | array( |
| 37 | 'styledComponent' => self::CONTAINER, |
| 38 | 'local' => true, |
| 39 | ) |
| 40 | ); |
| 41 | |
| 42 | $layout_media = $this->getPropByMedia( 'layout' ); |
| 43 | $row_layout_by_media = $row_block ? $row_block->getPropByMedia( 'layout' ) : array(); |
| 44 | |
| 45 | $column_width = $column_width_by_media['desktop']; |
| 46 | $layout_helper = new LayoutHelper( $layout_media, $row_layout_by_media ); |
| 47 | |
| 48 | $container_cls = LodashBasic::concat( |
| 49 | $layout_helper->getColumnLayoutClasses( $column_width_by_media ), |
| 50 | $layout_helper->getInheritedColumnVAlignClasses(), |
| 51 | get_post_class() |
| 52 | ); |
| 53 | |
| 54 | $equal_width = LodashBasic::get( $row_layout_by_media, 'desktop.equalWidth', false ); |
| 55 | |
| 56 | $align_cls = LodashBasic::concat( |
| 57 | $layout_helper->getColumnContentFlexBasis( $equal_width, $column_width ), |
| 58 | $layout_helper->getSelfVAlignClasses() |
| 59 | ); |
| 60 | |
| 61 | $inner = $layout_helper->getColumnInnerGapsClasses(); |
| 62 | |
| 63 | $map = array(); |
| 64 | $map[ self::CONTAINER ] = array( 'className' => $container_cls ); |
| 65 | $map[ self::ALIGN ] = array( 'className' => $align_cls ); |
| 66 | $map[ self::INNER ] = array( 'className' => $inner ); |
| 67 | |
| 68 | return $map; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @return string |
| 73 | */ |
| 74 | abstract public function loopBlockName(); |
| 75 | } |
| 76 |