PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.1
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / blocks / storeengine-coupon-form / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.11.1, at includes/blocks/storeengine-coupon-form/block.php

151 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\StoreengineCouponForm;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Helper;
11 use ABlocks\Controls\Typography;
12 use ABlocks\Controls\Background;
13 use ABlocks\Controls\Border;
14 use ABlocks\Controls\Dimensions;
15 use ABlocks\Controls\Range;
16 use ABlocks\Controls\BoxShadow;
17 use ABlocks\Controls\Color;
18
19 class Block extends BlockBaseAbstract {
20 protected $block_name = 'storeengine-coupon-form';
21
22 public function build_css( $attributes ) {
23 $css_generator = new CssGenerator( $attributes, $this->block_name );
24
25 $css_generator->add_class_styles(
26 '{{WRAPPER}} .storeengine-apply-coupon-form-shortcode .storeengine-ajax-apply-coupon-form',
27 $this->get_coupon_form_css( $attributes ),
28 $this->get_coupon_form_css( $attributes, 'Tablet' ),
29 $this->get_coupon_form_css( $attributes, 'Mobile' )
30 );
31 $css_generator->add_class_styles(
32 '{{WRAPPER}} .storeengine-apply-coupon-form-shortcode .storeengine-ajax-apply-coupon-form input[type=text]',
33 $this->get_coupon_form_input_css( $attributes ),
34 $this->get_coupon_form_input_css( $attributes, 'Tablet' ),
35 $this->get_coupon_form_input_css( $attributes, 'Mobile' )
36 );
37 $css_generator->add_class_styles(
38 '{{WRAPPER}} .storeengine-apply-coupon-form-shortcode .storeengine-ajax-apply-coupon-form input[type=text]:hover',
39 $this->get_coupon_form_input_hover_css( $attributes ),
40 $this->get_coupon_form_input_hover_css( $attributes, 'Tablet' ),
41 $this->get_coupon_form_input_hover_css( $attributes, 'Mobile' )
42 );
43 $css_generator->add_class_styles(
44 '{{WRAPPER}} .storeengine-apply-coupon-form-shortcode .storeengine-ajax-apply-coupon-form input[type=submit]',
45 $this->get_coupon_form_button_css( $attributes ),
46 $this->get_coupon_form_button_css( $attributes, 'Tablet' ),
47 $this->get_coupon_form_button_css( $attributes, 'Mobile' )
48 );
49 $css_generator->add_class_styles(
50 '{{WRAPPER}} .storeengine-apply-coupon-form-shortcode .storeengine-ajax-apply-coupon-form input[type=submit]:hover',
51 $this->get_coupon_form_button_hover_css( $attributes ),
52 $this->get_coupon_form_button_hover_css( $attributes, 'Tablet' ),
53 $this->get_coupon_form_button_hover_css( $attributes, 'Mobile' )
54 );
55
56 return $css_generator->generate_css();
57 }
58 public function get_coupon_form_css( $attributes, $device = '' ) {
59 $css = [];
60
61 if ( $attributes['direction'] !== '' ) {
62 $css['flex-direction'] = $attributes['direction'];
63 }
64
65 if ( ! empty( $attributes['formAlignment'][ 'value' . $device ] ) ) {
66 $css['justify-content'] = $attributes['formAlignment'][ 'value' . $device ];
67 }
68
69 return $css;
70
71 }
72
73 public function get_coupon_form_input_css( $attributes, $device = '' ) {
74 // $css = [];
75 // $css['width'] = $attributes['inputWidth'].'px';
76
77 return array_merge(
78 // $css,
79 Border::get_css( $attributes['inputBorder'], '', $device ),
80 Range::get_css([
81 'attributeValue' => $attributes['inputWidth'],
82 'attribute_object_key' => 'value',
83 'isResponsive' => true,
84 'hasUnit' => true,
85 'defaultValue' => 200,
86 'property' => 'width',
87 'unitDefaultValue' => 'px',
88 'device' => $device,
89 ]),
90 );
91
92 }
93
94 public function get_coupon_form_input_hover_css( $attributes, $device = '' ) {
95 return array_merge(
96 Border::get_hover_css( $attributes['inputBorder'] ?? [], '', $device ),
97 );
98 }
99
100 public function get_coupon_form_button_css( $attributes, $device = '' ) {
101 $typography = isset( $attributes['buttonTypography'] ) && is_array( $attributes['buttonTypography'] )
102 ? $attributes['buttonTypography']
103 : [];
104
105 $typography_value = array_merge( $typography, [ 'font-weight' => '400' ] );
106 $typgraphyGlobal = ( isset( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : '' );
107
108 if ( ! empty( $attributes['padding'] ) ) {
109 $cssPadding = Dimensions::get_css( $attributes['padding'], 'padding', $device );
110 }
111
112 return array_merge(
113 [ 'color' => Color::get_css( isset( $attributes['buttonColor'] ) ? $attributes['buttonColor'] : '' ) ],
114 [ 'background' => Color::get_css( isset( $attributes['buttonBackground'] ) ? $attributes['buttonBackground'] : '' ) ],
115 Typography::get_css( $typography_value, '', $device, $typgraphyGlobal ),
116 Border::get_css( $attributes['buttonBorder'], '', $device ),
117 $cssPadding,
118 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
119 Range::get_css([
120 'attributeValue' => $attributes['buttonWidth'],
121 'attribute_object_key' => 'value',
122 'isResponsive' => true,
123 'hasUnit' => true,
124 'defaultValue' => 200,
125 'property' => 'width',
126 'unitDefaultValue' => 'px',
127 'device' => $device,
128 ]),
129 );
130 }
131 public function get_coupon_form_button_hover_css( $attributes, $device = '' ) {
132 return array_merge(
133 Border::get_hover_css( $attributes['buttonBorder'] ?? [], '', $device ),
134 BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device ),
135 [ 'color' => Color::get_css( isset( $attributes['buttonColorH'] ) ? $attributes['buttonColorH'] : '' ) ],
136 [ 'background' => Color::get_css( isset( $attributes['buttonBackgroundH'] ) ? $attributes['buttonBackgroundH'] : '' ) ]
137 );
138 }
139
140
141 public function render_block_content( $attributes, $content, $block_instance ) {
142 $attr_array = [
143 'placeholder' => Helper::get_attribute_value( $attributes, 'input_placeholder' ),
144 'buttonTitle' => Helper::get_attribute_value( $attributes, 'buttonTitle' ),
145 ];
146 $shortcode = '[storeengine_apply_coupon_form ' . Helper::attr_shortcode( $attr_array ) . ']';
147 echo do_shortcode( $shortcode );
148 }
149
150 }
151