Separators.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Core\Separators; |
| 4 | |
| 5 | use Kubio\Config; |
| 6 | use Kubio\Core\Element; |
| 7 | use Kubio\Core\LodashBasic; |
| 8 | |
| 9 | class Separators extends Element { |
| 10 | function __construct( $tag_name, $props, $children, $block ) { |
| 11 | parent::__construct( Element::FRAGMENT, $props, $children, $block ); |
| 12 | |
| 13 | $topEnabledByMedia = array(); |
| 14 | $bottomEnabledByMedia = array(); |
| 15 | if ( $block ) { |
| 16 | $this->value = $this->block->separators(); |
| 17 | $topEnabledByMedia = $this->block->separatorTopEnabledByMedia(); |
| 18 | $bottomEnabledByMedia = $this->block->separatorBottomEnabledByMedia(); |
| 19 | } |
| 20 | |
| 21 | $default = Config::value( 'definitions.separator.default' ); |
| 22 | |
| 23 | $top = $this->get( 'top', array() ); |
| 24 | $bottom = $this->get( 'bottom', array() ); |
| 25 | |
| 26 | $shouldDisplayTopSeparator = in_array( true, array_values( $topEnabledByMedia ) ); |
| 27 | $shouldDisplayBottomSeparator = in_array( true, array_values( $bottomEnabledByMedia ) ); |
| 28 | |
| 29 | $separators = array(); |
| 30 | if ( $shouldDisplayTopSeparator ) { |
| 31 | $separators[] = new Separator( |
| 32 | Element::DIV, |
| 33 | LodashBasic::merge( |
| 34 | $default, |
| 35 | $top, |
| 36 | array( |
| 37 | 'position' => 'top', |
| 38 | 'enabledByMedia' => $topEnabledByMedia, |
| 39 | ) |
| 40 | ), |
| 41 | array(), |
| 42 | $block |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | if ( $shouldDisplayBottomSeparator ) { |
| 47 | $separators[] = new Separator( |
| 48 | Element::DIV, |
| 49 | LodashBasic::merge( |
| 50 | $default, |
| 51 | $bottom, |
| 52 | array( |
| 53 | 'position' => 'bottom', |
| 54 | 'enabledByMedia' => $bottomEnabledByMedia, |
| 55 | ) |
| 56 | ), |
| 57 | array(), |
| 58 | $block |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | $this->children = $separators; |
| 63 | } |
| 64 | } |
| 65 |