PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 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 All 81 releases
← All changes | includes/blocks/storeengine-coupon-form/block.php +155 -0 2.7.5 → 2.14.0 View file →
@@ -1,0 +1,155 @@
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 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coupon_form_css( $attributes, $device ); } )
31 + );
32 + $css_generator->add_class_styles(
33 + '{{WRAPPER}} .storeengine-apply-coupon-form-shortcode .storeengine-ajax-apply-coupon-form input[type=text]',
34 + $this->get_coupon_form_input_css( $attributes ),
35 + $this->get_coupon_form_input_css( $attributes, 'Tablet' ),
36 + $this->get_coupon_form_input_css( $attributes, 'Mobile' ),
37 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coupon_form_input_css( $attributes, $device ); } )
38 + );
39 + $css_generator->add_class_styles(
40 + '{{WRAPPER}} .storeengine-apply-coupon-form-shortcode .storeengine-ajax-apply-coupon-form input[type=text]:hover',
41 + $this->get_coupon_form_input_hover_css( $attributes ),
42 + $this->get_coupon_form_input_hover_css( $attributes, 'Tablet' ),
43 + $this->get_coupon_form_input_hover_css( $attributes, 'Mobile' ),
44 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coupon_form_input_hover_css( $attributes, $device ); } )
45 + );
46 + $css_generator->add_class_styles(
47 + '{{WRAPPER}} .storeengine-apply-coupon-form-shortcode .storeengine-ajax-apply-coupon-form input[type=submit]',
48 + $this->get_coupon_form_button_css( $attributes ),
49 + $this->get_coupon_form_button_css( $attributes, 'Tablet' ),
50 + $this->get_coupon_form_button_css( $attributes, 'Mobile' ),
51 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coupon_form_button_css( $attributes, $device ); } )
52 + );
53 + $css_generator->add_class_styles(
54 + '{{WRAPPER}} .storeengine-apply-coupon-form-shortcode .storeengine-ajax-apply-coupon-form input[type=submit]:hover',
55 + $this->get_coupon_form_button_hover_css( $attributes ),
56 + $this->get_coupon_form_button_hover_css( $attributes, 'Tablet' ),
57 + $this->get_coupon_form_button_hover_css( $attributes, 'Mobile' ),
58 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_coupon_form_button_hover_css( $attributes, $device ); } )
59 + );
60 +
61 + return $css_generator->generate_css();
62 + }
63 + public function get_coupon_form_css( $attributes, $device = '' ) {
64 + $css = [];
65 +
66 + if ( $attributes['direction'] !== '' ) {
67 + $css['flex-direction'] = $attributes['direction'];
68 + }
69 +
70 + if ( ! empty( $attributes['formAlignment'][ 'value' . $device ] ) ) {
71 + $css['justify-content'] = $attributes['formAlignment'][ 'value' . $device ];
72 + }
73 +
74 + return $css;
75 +
76 + }
77 +
78 + public function get_coupon_form_input_css( $attributes, $device = '' ) {
79 + // $css = [];
80 + // $css['width'] = $attributes['inputWidth'].'px';
81 +
82 + return array_merge(
83 + // $css,
84 + Border::get_css( $attributes['inputBorder'], '', $device ),
85 + Range::get_css([
86 + 'attributeValue' => $attributes['inputWidth'],
87 + 'attribute_object_key' => 'value',
88 + 'isResponsive' => true,
89 + 'hasUnit' => true,
90 + 'defaultValue' => 200,
91 + 'property' => 'width',
92 + 'unitDefaultValue' => 'px',
93 + 'device' => $device,
94 + ]),
95 + );
96 +
97 + }
98 +
99 + public function get_coupon_form_input_hover_css( $attributes, $device = '' ) {
100 + return array_merge(
101 + Border::get_hover_css( $attributes['inputBorder'] ?? [], '', $device ),
102 + );
103 + }
104 +
105 + public function get_coupon_form_button_css( $attributes, $device = '' ) {
106 + $typography = isset( $attributes['buttonTypography'] ) && is_array( $attributes['buttonTypography'] )
107 + ? $attributes['buttonTypography']
108 + : [];
109 +
110 + $typography_value = array_merge( $typography, [ 'font-weight' => '400' ] );
111 + $typgraphyGlobal = ( isset( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : '' );
112 +
113 + if ( ! empty( $attributes['padding'] ) ) {
114 + $cssPadding = Dimensions::get_css( $attributes['padding'], 'padding', $device );
115 + }
116 +
117 + return array_merge(
118 + [ 'color' => Color::get_css( isset( $attributes['buttonColor'] ) ? $attributes['buttonColor'] : '' ) ],
119 + [ 'background' => Color::get_css( isset( $attributes['buttonBackground'] ) ? $attributes['buttonBackground'] : '' ) ],
120 + Typography::get_css( $typography_value, '', $device, $typgraphyGlobal ),
121 + Border::get_css( $attributes['buttonBorder'], '', $device ),
122 + $cssPadding,
123 + BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
124 + Range::get_css([
125 + 'attributeValue' => $attributes['buttonWidth'],
126 + 'attribute_object_key' => 'value',
127 + 'isResponsive' => true,
128 + 'hasUnit' => true,
129 + 'defaultValue' => 200,
130 + 'property' => 'width',
131 + 'unitDefaultValue' => 'px',
132 + 'device' => $device,
133 + ]),
134 + );
135 + }
136 + public function get_coupon_form_button_hover_css( $attributes, $device = '' ) {
137 + return array_merge(
138 + Border::get_hover_css( $attributes['buttonBorder'] ?? [], '', $device ),
139 + BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device ),
140 + [ 'color' => Color::get_css( isset( $attributes['buttonColorH'] ) ? $attributes['buttonColorH'] : '' ) ],
141 + [ 'background' => Color::get_css( isset( $attributes['buttonBackgroundH'] ) ? $attributes['buttonBackgroundH'] : '' ) ]
142 + );
143 + }
144 +
145 +
146 + public function render_block_content( $attributes, $content, $block_instance ) {
147 + $attr_array = [
148 + 'placeholder' => Helper::get_attribute_value( $attributes, 'input_placeholder' ),
149 + 'buttonTitle' => Helper::get_attribute_value( $attributes, 'buttonTitle' ),
150 + ];
151 + $shortcode = '[storeengine_apply_coupon_form ' . Helper::attr_shortcode( $attr_array ) . ']';
152 + echo do_shortcode( $shortcode );
153 + }
154 +
155 +}