| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\Paragraph; |
| 3 |
|
| 4 |
use ABlocks\Classes\BlockBaseAbstract; |
| 5 |
use ABlocks\Classes\CssGenerator; |
| 6 |
use ABlocks\Controls\Alignment; |
| 7 |
use ABlocks\Controls\TextShadow; |
| 8 |
use ABlocks\Controls\TextStroke; |
| 9 |
use ABlocks\Controls\Typography; |
| 10 |
|
| 11 |
class Block extends BlockBaseAbstract { |
| 12 |
protected $block_name = 'paragraph'; |
| 13 |
|
| 14 |
public function build_css( $attributes ) { |
| 15 |
|
| 16 |
$css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 17 |
|
| 18 |
$css_generator->add_class_styles( |
| 19 |
'{{WRAPPER}}', |
| 20 |
$this->get_wrapper_css( $attributes ), |
| 21 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 22 |
$this->get_wrapper_css( $attributes, 'Mobile' ), |
| 23 |
); |
| 24 |
|
| 25 |
$desktop_paragraph_text_style = $this->get_paragraph_text_css( $attributes ); |
| 26 |
|
| 27 |
if ( ! empty( $attributes['textColor'] ) ) { |
| 28 |
$desktop_paragraph_text_style['color'] = $attributes['textColor']; |
| 29 |
} |
| 30 |
$css_generator->add_class_styles( |
| 31 |
'{{WRAPPER}} .ablocks-paragraph-text', |
| 32 |
$desktop_paragraph_text_style, |
| 33 |
$this->get_paragraph_text_css( $attributes, 'Tablet' ), |
| 34 |
$this->get_paragraph_text_css( $attributes, 'Mobile' ), |
| 35 |
); |
| 36 |
|
| 37 |
$css_generator->add_class_styles( |
| 38 |
'{{WRAPPER}} .ablocks-paragraph-text-drop-caps::first-letter', |
| 39 |
$this->get_paragraph_drop_text_css( $attributes ), |
| 40 |
$this->get_paragraph_drop_text_css( $attributes, 'Tablet' ), |
| 41 |
$this->get_paragraph_drop_text_css( $attributes, 'Mobile' ), |
| 42 |
); |
| 43 |
return $css_generator->generate_css(); |
| 44 |
} |
| 45 |
|
| 46 |
public function get_wrapper_css( $attributes, $device = '' ) { |
| 47 |
return isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'text-align', $device ) : []; |
| 48 |
} |
| 49 |
|
| 50 |
public function get_paragraph_text_css( $attributes, $device = '' ) { |
| 51 |
return array_merge( |
| 52 |
isset( $attributes['typography'] ) ? Typography::get_css( $attributes['typography'], '', $device ) : [], |
| 53 |
isset( $attributes['textStroke'] ) ? TextStroke::get_css( $attributes['textStroke'], '', $device ) : [], |
| 54 |
isset( $attributes['textShadow'] ) ? TextShadow::get_css( $attributes['textShadow'], '', $device ) : [], |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
public function get_paragraph_drop_text_css( $attributes, $device = '' ) { |
| 59 |
$css = []; |
| 60 |
if ( ! empty( $attributes['dropCapsTextColor'] ) ) { |
| 61 |
$css['color'] = $attributes['dropCapsTextColor']; |
| 62 |
} |
| 63 |
return $css; |
| 64 |
} |
| 65 |
} |
| 66 |
|