| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\AcademyStudentRegistrationForm; |
| 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 |
|
| 16 |
|
| 17 |
class Block extends BlockBaseAbstract { |
| 18 |
protected $block_name = 'academy-student-registration-form'; |
| 19 |
|
| 20 |
public function __construct() { |
| 21 |
parent::__construct(); |
| 22 |
|
| 23 |
add_filter( 'academy/shortcode/student_registration_form_is_user_logged_in', [ $this, 'force_showing_student_registration_form_in_editor' ] ); |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
public function force_showing_student_registration_form_in_editor( $flag ) { |
| 28 |
|
| 29 |
if ( Helper::is_gutenberg_editor() ) { |
| 30 |
return false; |
| 31 |
} |
| 32 |
return $flag; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
public function build_css( $attributes ) { |
| 37 |
$css_generator = new CssGenerator( $attributes ); |
| 38 |
|
| 39 |
$input_field_label_desktop_css = $this->get_form_input_label_css( $attributes ); |
| 40 |
if ( ! empty( $attributes['input_label_color'] ) ) { |
| 41 |
$input_field_label_desktop_css['color'] = $attributes['input_label_color']; |
| 42 |
} |
| 43 |
$css_generator->add_class_styles( |
| 44 |
'{{WRAPPER}} .academy-reg-form--student .academy-form-group label', |
| 45 |
$input_field_label_desktop_css, |
| 46 |
$this->get_form_input_label_css( $attributes, 'Tablet' ), |
| 47 |
$this->get_form_input_label_css( $attributes, 'Mobile' ) |
| 48 |
); |
| 49 |
|
| 50 |
$css_generator->add_class_styles( |
| 51 |
'{{WRAPPER}} .academy-reg-form--student .academy-form-group label:hover', |
| 52 |
$this->get_form_input_label_hover_css( $attributes ), |
| 53 |
$this->get_form_input_label_hover_css( $attributes, 'Tablet' ), |
| 54 |
$this->get_form_input_label_hover_css( $attributes, 'Mobile' ) |
| 55 |
); |
| 56 |
|
| 57 |
$css_generator->add_class_styles( |
| 58 |
'{{WRAPPER}} .academy-reg-form--student .academy-form-group input', |
| 59 |
$this->get_form_input_field_css( $attributes ), |
| 60 |
$this->get_form_input_field_css( $attributes, 'Tablet' ), |
| 61 |
$this->get_form_input_field_css( $attributes, 'Mobile' ) |
| 62 |
); |
| 63 |
$css_generator->add_class_styles( |
| 64 |
'{{WRAPPER}} .academy-reg-form--student .academy-form-group input:hover', |
| 65 |
$this->get_form_input_field_hover_css( $attributes ), |
| 66 |
$this->get_form_input_field_hover_css( $attributes, 'Tablet' ), |
| 67 |
$this->get_form_input_field_hover_css( $attributes, 'Mobile' ) |
| 68 |
); |
| 69 |
|
| 70 |
$css_generator->add_class_styles( |
| 71 |
'{{WRAPPER}} .academy-reg-form--student .academy-form-group input::placeholder', |
| 72 |
$this->get_form_input_field_placeholder_css( $attributes ), |
| 73 |
$this->get_form_input_field_placeholder_css( $attributes, 'Tablet' ), |
| 74 |
$this->get_form_input_field_placeholder_css( $attributes, 'Mobile' ) |
| 75 |
); |
| 76 |
|
| 77 |
$css_generator->add_class_styles( |
| 78 |
'{{WRAPPER}} .academy-reg-form--student .academy-form-group button', |
| 79 |
$this->get_form_button_css( $attributes ), |
| 80 |
$this->get_form_button_css( $attributes, 'Tablet' ), |
| 81 |
$this->get_form_button_css( $attributes, 'Mobile' ) |
| 82 |
); |
| 83 |
|
| 84 |
$css_generator->add_class_styles( |
| 85 |
'{{WRAPPER}} .academy-reg-form--student .academy-form-group button:hover', |
| 86 |
$this->get_form_button_hover_css( $attributes ), |
| 87 |
$this->get_form_button_hover_css( $attributes, 'Tablet' ), |
| 88 |
$this->get_form_button_hover_css( $attributes, 'Mobile' ) |
| 89 |
); |
| 90 |
|
| 91 |
$css_generator->add_class_styles( |
| 92 |
'{{WRAPPER}} .academy-reg-form', |
| 93 |
$this->get_form_css( $attributes ), |
| 94 |
$this->get_form_css( $attributes, 'Tablet' ), |
| 95 |
$this->get_form_css( $attributes, 'Mobile' ) |
| 96 |
); |
| 97 |
$css_generator->add_class_styles( |
| 98 |
'{{WRAPPER}} .academy-reg-form:hover', |
| 99 |
$this->get_form_hover_css( $attributes ), |
| 100 |
$this->get_form_hover_css( $attributes, 'Tablet' ), |
| 101 |
$this->get_form_hover_css( $attributes, 'Mobile' ) |
| 102 |
); |
| 103 |
|
| 104 |
return $css_generator->generate_css(); |
| 105 |
} |
| 106 |
|
| 107 |
public function get_form_input_label_css( $attributes, $device = '' ) { |
| 108 |
$input_label_typography_css = ! empty( $attributes['input_label_typhography'] ) ? Typography::get_css( $attributes['input_label_typhography'], '', $device ) : array(); |
| 109 |
return $input_label_typography_css; |
| 110 |
} |
| 111 |
|
| 112 |
public function get_form_input_label_hover_css( $attributes, $device = '' ) { |
| 113 |
$css = array(); |
| 114 |
if ( ! empty( $attributes['input_label_hover_color'] ) ) { |
| 115 |
$css['color'] = $attributes['input_label_hover_color']; |
| 116 |
} |
| 117 |
return $css; |
| 118 |
} |
| 119 |
|
| 120 |
public function get_form_input_field_css( $attributes, $device = '' ) { |
| 121 |
$css = array(); |
| 122 |
$input_field_border_css = ! empty( $attributes['form_field_border'] ) ? Border::get_css( $attributes['form_field_border'], '', $device ) : array(); |
| 123 |
if ( ! empty( $attributes['input_field_color'] ) ) { |
| 124 |
$css['color'] = $attributes['input_field_color']; |
| 125 |
} |
| 126 |
if ( ! empty( $attributes['input_field_bg_color'] ) ) { |
| 127 |
$css['background'] = $attributes['input_field_bg_color']; |
| 128 |
} |
| 129 |
|
| 130 |
return array_merge( |
| 131 |
$input_field_border_css, |
| 132 |
$css, |
| 133 |
); |
| 134 |
} |
| 135 |
|
| 136 |
public function get_form_input_field_hover_css( $attributes, $device = '' ) { |
| 137 |
$css = array(); |
| 138 |
$input_field_border_hover_css = ! empty( $attributes['form_field_border'] ) ? Border::get_hover_css( $attributes['form_field_border'], '', $device ) : array(); |
| 139 |
|
| 140 |
return array_merge( |
| 141 |
$input_field_border_hover_css, |
| 142 |
$css, |
| 143 |
); |
| 144 |
} |
| 145 |
public function get_form_input_field_placeholder_css( $attributes, $device = '' ) { |
| 146 |
$css = array(); |
| 147 |
if ( ! empty( $attributes['input_field_placeholder_color'] ) ) { |
| 148 |
$css['color'] = $attributes['input_field_placeholder_color']; |
| 149 |
} |
| 150 |
|
| 151 |
return $css; |
| 152 |
} |
| 153 |
|
| 154 |
public function get_form_button_css( $attributes, $device = '' ) { |
| 155 |
$css = array(); |
| 156 |
if ( ! empty( $attributes['form_button_background'] ) ) { |
| 157 |
$css['background'] = $attributes['form_button_background']; |
| 158 |
} |
| 159 |
if ( ! empty( $attributes['form_button_color'] ) ) { |
| 160 |
$css['color'] = $attributes['form_button_color']; |
| 161 |
} |
| 162 |
$form_button_typography_css = ! empty( $attributes['form_button_typhography'] ) ? Typography::get_css( $attributes['form_button_typhography'], '', $device ) : array(); |
| 163 |
$form_button_padding = ! empty( $attributes['form_button_padding'] ) ? Dimensions::get_css( $attributes['form_button_padding'], 'padding', $device ) : array(); |
| 164 |
$form_button_border_css = ! empty( $attributes['form_button_border'] ) ? Border::get_css( $attributes['form_button_border'], '', $device ) : array(); |
| 165 |
return array_merge( |
| 166 |
$form_button_typography_css, |
| 167 |
$form_button_padding, |
| 168 |
$form_button_border_css, |
| 169 |
$css |
| 170 |
); |
| 171 |
} |
| 172 |
|
| 173 |
public function get_form_css( $attributes, $device = '' ) { |
| 174 |
$form_background = ! empty( $attributes['form_background'] ) ? Background::get_css( $attributes['form_background'], 'background', $device ) : array(); |
| 175 |
$form_padding = ! empty( $attributes['form_padding'] ) ? Dimensions::get_css( $attributes['form_padding'], 'padding', $device ) : array(); |
| 176 |
$form_border = ! empty( $attributes['form_border'] ) ? Border::get_css( $attributes['form_border'], '', $device ) : array(); |
| 177 |
|
| 178 |
return array_merge( |
| 179 |
$form_background, |
| 180 |
$form_padding, |
| 181 |
$form_border |
| 182 |
); |
| 183 |
} |
| 184 |
public function get_form_hover_css( $attributes, $device = '' ) { |
| 185 |
$form_hover_background = ! empty( $attributes['form_background'] ) ? Background::get_hover_css( $attributes['form_background'], 'background', $device ) : array(); |
| 186 |
$form_hover_border = ! empty( $attributes['form_border'] ) ? Border::get_hover_css( $attributes['form_border'], '', $device ) : array(); |
| 187 |
|
| 188 |
return array_merge( |
| 189 |
$form_hover_background, |
| 190 |
$form_hover_border |
| 191 |
); |
| 192 |
} |
| 193 |
|
| 194 |
public function get_form_button_hover_css( $attributes, $device = '' ) { |
| 195 |
$css = array(); |
| 196 |
if ( ! empty( $attributes['form_button_hover_background'] ) ) { |
| 197 |
$css['background'] = $attributes['form_button_hover_background']; |
| 198 |
} |
| 199 |
if ( ! empty( $attributes['form_button_hover_color'] ) ) { |
| 200 |
$css['color'] = $attributes['form_button_hover_color']; |
| 201 |
} |
| 202 |
|
| 203 |
$form_button_border = ! empty( $attributes['form_button_border'] ) ? Border::get_hover_css( $attributes['form_button_border'], '', $device ) : array(); |
| 204 |
|
| 205 |
return array_merge( |
| 206 |
$css, |
| 207 |
$form_button_border |
| 208 |
); |
| 209 |
} |
| 210 |
|
| 211 |
public function render_block_content( $attributes, $content, $block_instance ) { |
| 212 |
|
| 213 |
$shortcode = '[academy_student_registration_form]'; |
| 214 |
echo do_shortcode( $shortcode ); |
| 215 |
|
| 216 |
} |
| 217 |
|
| 218 |
} |
| 219 |
|