| @@ -6,37 +6,41 @@ | ||
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | use ABlocks\Classes\BlockBaseAbstract; |
| 9 | 9 | use ABlocks\Classes\CssGenerator; |
| 10 | +use ABlocks\Classes\CssGeneratorV2; | |
| 10 | 11 | use ABlocks\Helper; |
| 11 | 12 | use ABlocks\Controls\Typography; |
| 12 | 13 | use ABlocks\Controls\Background; |
| 13 | 14 | use ABlocks\Controls\Border; |
| 14 | 15 | use ABlocks\Controls\Dimensions; |
| 15 | - | |
| 16 | +use ABlocks\Controls\Color; | |
| 16 | 17 | class Block extends BlockBaseAbstract { |
| 17 | 18 | protected $block_name = 'academy-course-search'; |
| 18 | 19 | |
| 19 | 20 | public function build_css( $attributes ) { |
| 20 | - $css_generator = new CssGenerator( $attributes ); | |
| 21 | + $css_generator = new CssGeneratorV2( $attributes, $this->block_name ); | |
| 21 | 22 | |
| 22 | 23 | $css_generator->add_class_styles( |
| 23 | 24 | '{{WRAPPER}} .academy-search-form-wrap .academy-search-form__field-input', |
| 24 | 25 | $this->get_search_form_css( $attributes ), |
| 25 | 26 | $this->get_search_form_css( $attributes, 'Tablet' ), |
| 26 | - $this->get_search_form_css( $attributes, 'Mobile' ) | |
| 27 | + $this->get_search_form_css( $attributes, 'Mobile' ), | |
| 28 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_search_form_css( $attributes, $device ); } ) | |
| 27 | 29 | ); |
| 28 | 30 | $css_generator->add_class_styles( |
| 29 | 31 | '{{WRAPPER}} .academy-search-form-wrap .academy-search-form__field-input:hover', |
| 30 | 32 | $this->get_search_form_hover_css( $attributes ), |
| 31 | 33 | $this->get_search_form_hover_css( $attributes, 'Tablet' ), |
| 32 | - $this->get_search_form_hover_css( $attributes, 'Mobile' ) | |
| 34 | + $this->get_search_form_hover_css( $attributes, 'Mobile' ), | |
| 35 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_search_form_hover_css( $attributes, $device ); } ) | |
| 33 | 36 | ); |
| 34 | 37 | $css_generator->add_class_styles( |
| 35 | 38 | '{{WRAPPER}} .academy-search-form-wrap .academy-search-form__field-icon span', |
| 36 | 39 | $this->get_search_box_icon_css( $attributes ), |
| 37 | 40 | $this->get_search_box_icon_css( $attributes, 'Tablet' ), |
| 38 | - $this->get_search_box_icon_css( $attributes, 'Mobile' ) | |
| 41 | + $this->get_search_box_icon_css( $attributes, 'Mobile' ), | |
| 42 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_search_box_icon_css( $attributes, $device ); } ) | |
| 39 | 43 | ); |
| 40 | 44 | |
| 41 | 45 | $css_generator->add_class_styles( |
| 42 | 46 | '{{WRAPPER}} .academy-search-form-wrap .academy-search-form__field-input::placeholder', |
| @@ -41,9 +45,10 @@ | ||
| 41 | 45 | $css_generator->add_class_styles( |
| 42 | 46 | '{{WRAPPER}} .academy-search-form-wrap .academy-search-form__field-input::placeholder', |
| 43 | 47 | $this->get_search_box_placeholder_css( $attributes ), |
| 44 | 48 | $this->get_search_box_placeholder_css( $attributes, 'Tablet' ), |
| 45 | - $this->get_search_box_placeholder_css( $attributes, 'Mobile' ) | |
| 49 | + $this->get_search_box_placeholder_css( $attributes, 'Mobile' ), | |
| 50 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_search_box_placeholder_css( $attributes, $device ); } ) | |
| 46 | 51 | ); |
| 47 | 52 | |
| 48 | 53 | return $css_generator->generate_css(); |
| 49 | 54 | } |
| @@ -48,24 +53,18 @@ | ||
| 48 | 53 | return $css_generator->generate_css(); |
| 49 | 54 | } |
| 50 | 55 | |
| 51 | 56 | |
| 52 | - | |
| 53 | 57 | public function get_search_form_css( $attributes, $device = '' ) { |
| 54 | - $css = array(); | |
| 55 | - if ( ! empty( $attributes['search_background_color'] ) ) { | |
| 56 | - $css['background'] = $attributes['search_background_color']; | |
| 57 | - } | |
| 58 | - if ( ! empty( $attributes['search_box_color'] ) ) { | |
| 59 | - $css['color'] = $attributes['search_box_color']; | |
| 60 | - } | |
| 61 | - $search_typography_css = ! empty( $attributes['search_typography'] ) ? Typography::get_css( $attributes['search_typography'], '', $device ) : array(); | |
| 58 | + $typographyValueGlobal = ! empty( $attributes['search_typographyGlobal'] ) ? $attributes['search_typographyGlobal'] : ''; | |
| 59 | + $typography_value = isset( $attributes['search_typography'] ) ? $attributes['search_typography'] : []; | |
| 62 | 60 | $search_border_css = ! empty( $attributes['search_border'] ) ? Border::get_css( $attributes['search_border'], '', $device ) : array(); |
| 63 | 61 | |
| 64 | 62 | return array_merge( |
| 65 | - $search_typography_css, | |
| 63 | + Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), | |
| 66 | 64 | $search_border_css, |
| 67 | - $css, | |
| 65 | + [ 'color' => Color::get_css( isset( $attributes['search_box_color'] ) ? $attributes['search_box_color'] : '' ) ], | |
| 66 | + [ 'background' => Color::get_css( isset( $attributes['search_background_color'] ) ? $attributes['search_background_color'] : '' ) ], | |
| 68 | 67 | ); |
| 69 | 68 | } |
| 70 | 69 | public function get_search_form_hover_css( $attributes, $device = '' ) { |
| 71 | 70 | $css = array(); |
| @@ -77,32 +76,18 @@ | ||
| 77 | 76 | $css, |
| 78 | 77 | ); |
| 79 | 78 | } |
| 80 | 79 | public function get_search_box_icon_css( $attributes, $device = '' ) { |
| 81 | - $css = array(); | |
| 82 | - | |
| 83 | - if ( ! empty( $attributes['search_icon_color'] ) ) { | |
| 84 | - $css['color'] = $attributes['search_icon_color']; | |
| 85 | - } | |
| 86 | - | |
| 87 | - return $css; | |
| 80 | + return [ 'color' => Color::get_css( isset( $attributes['search_icon_color'] ) ? $attributes['search_icon_color'] : '' ) ]; | |
| 88 | 81 | } |
| 89 | 82 | public function get_search_box_placeholder_css( $attributes, $device = '' ) { |
| 90 | - $css = array(); | |
| 91 | - | |
| 92 | - if ( ! empty( $attributes['search_placeholder_color'] ) ) { | |
| 93 | - $css['color'] = $attributes['search_placeholder_color']; | |
| 94 | - } | |
| 95 | - | |
| 96 | - return $css; | |
| 83 | + return [ 'color' => Color::get_css( isset( $attributes['search_placeholder_color'] ) ? $attributes['search_placeholder_color'] : '' ) ]; | |
| 97 | 84 | } |
| 98 | 85 | |
| 99 | 86 | |
| 100 | - | |
| 101 | - | |
| 102 | 87 | public function render_block_content( $attributes, $content, $block_instance ) { |
| 103 | 88 | $attr_array = [ |
| 104 | - 'placeholder' => Helper::get_attribute_value( $attributes, 'placeholder' ), | |
| 89 | + 'placeholder' => sanitize_text_field( Helper::get_attribute_value( $attributes, 'placeholder' ) ), | |
| 105 | 90 | ]; |
| 106 | 91 | $shortcode = '[academy_course_search ' . Helper::attr_shortcode( $attr_array ) . ']'; |
| 107 | 92 | echo do_shortcode( $shortcode ); |
| 108 | 93 | } |