Helper.php
1 year ago
OxygenBuilder.php
1 year ago
OxygenElement.php
1 year ago
OxygenFormWidget.php
2 months ago
OxygenFormWidget.php
293 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Oxygen form widget. |
| 4 | * |
| 5 | * @since 3.0.5 |
| 6 | * @package EverestForms\Addons\OxygenBuilder\OxygenFormWidget |
| 7 | */ |
| 8 | namespace EverestForms\Addons\OxygenBuilder; |
| 9 | |
| 10 | use EverestForms\Addons\OxygenBuilder\OxygenElement; |
| 11 | |
| 12 | class OxygenFormWidget extends OxygenElement { |
| 13 | |
| 14 | public $css_added = false; |
| 15 | |
| 16 | /** |
| 17 | * Name. |
| 18 | * |
| 19 | * @since 3.0.5 |
| 20 | */ |
| 21 | public function name() { |
| 22 | return __( 'Forms', 'everest-forms' ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Slug. |
| 27 | * |
| 28 | * @since 3.0.5 |
| 29 | */ |
| 30 | public function slug() { |
| 31 | return 'evf_form_widget'; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Accordion place. |
| 36 | * |
| 37 | * @since 3.0.5 |
| 38 | */ |
| 39 | public function accordion_button_place() { |
| 40 | return 'form'; |
| 41 | } |
| 42 | /** |
| 43 | * Enqueue the styles. |
| 44 | * |
| 45 | * @since 3.0.5 |
| 46 | */ |
| 47 | public function custom_init() { |
| 48 | wp_register_style( 'everest-forms-admin', evf()->plugin_url() . '/assets/css/admin.css', array(), EVF_VERSION ); |
| 49 | wp_register_style( 'everest-forms-general', evf()->plugin_url() . '/assets/css/everest-forms.css', array(), EVF_VERSION ); |
| 50 | |
| 51 | wp_enqueue_style( 'everest-forms-admin' ); |
| 52 | wp_enqueue_style( 'everest-forms-general' ); |
| 53 | } |
| 54 | /** |
| 55 | * Icon. |
| 56 | * |
| 57 | * @since 3.0.5 |
| 58 | */ |
| 59 | public function icon() { |
| 60 | return \EVF_Admin_Menus::get_icon_svg(); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Add controls. |
| 65 | * |
| 66 | * @since 3.0.5 |
| 67 | */ |
| 68 | public function controls() { |
| 69 | $templates_control = $this->addOptionControl( |
| 70 | array( |
| 71 | 'type' => 'dropdown', |
| 72 | 'name' => __( 'Select a Form', 'everest-forms' ), |
| 73 | 'slug' => 'evf_form', |
| 74 | 'value' => Helper::get_form_list(), |
| 75 | 'default' => 'no', |
| 76 | 'css' => false, |
| 77 | ) |
| 78 | ); |
| 79 | |
| 80 | $templates_control->rebuildElementOnChange(); |
| 81 | |
| 82 | $this->form_container_style_controls(); |
| 83 | $this->form_input_labels_style(); |
| 84 | $this->submit_btn_style(); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Form contrainer style controls. |
| 89 | * |
| 90 | * @since 3.0.5 |
| 91 | */ |
| 92 | public function form_container_style_controls() { |
| 93 | $section_container = $this->addControlSection( |
| 94 | 'evf_container', |
| 95 | __( 'Form Container', 'everest-forms' ), |
| 96 | 'assets/icon.png', |
| 97 | $this |
| 98 | ); |
| 99 | $selector = '.everest-forms'; |
| 100 | $section_container->addStyleControls( |
| 101 | array( |
| 102 | array( |
| 103 | 'name' => __( 'Background Color', 'everest-forms' ), |
| 104 | 'selector' => $selector, |
| 105 | 'property' => 'background-color', |
| 106 | ), |
| 107 | array( |
| 108 | 'name' => __( 'Max Width', 'everest-forms' ), |
| 109 | 'selector' => $selector, |
| 110 | 'property' => 'width', |
| 111 | ), |
| 112 | ) |
| 113 | ); |
| 114 | |
| 115 | $section_container->addPreset( |
| 116 | 'padding', |
| 117 | 'evf_container_padding', |
| 118 | __( 'Padding', 'everest-forms' ), |
| 119 | $selector |
| 120 | )->whiteList(); |
| 121 | |
| 122 | $section_container->addPreset( |
| 123 | 'margin', |
| 124 | 'evf_container_margin', |
| 125 | __( 'Margin', 'everest-forms' ), |
| 126 | $selector |
| 127 | )->whiteList(); |
| 128 | |
| 129 | $section_container->addPreset( |
| 130 | 'border', |
| 131 | 'evf_container_border', |
| 132 | __( 'Border', 'everest-forms' ), |
| 133 | $selector |
| 134 | )->whiteList(); |
| 135 | |
| 136 | $section_container->addPreset( |
| 137 | 'border-radius', |
| 138 | 'evf_container_radius', |
| 139 | __( 'Border Radius', 'everest-forms' ), |
| 140 | $selector |
| 141 | )->whiteList(); |
| 142 | |
| 143 | $section_container->boxShadowSection( |
| 144 | __( 'Box Shadow', 'everest-forms' ), |
| 145 | $selector, |
| 146 | $this |
| 147 | ); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Field input label styles. |
| 152 | * |
| 153 | * @since 3.0.5 |
| 154 | */ |
| 155 | public function form_input_labels_style() { |
| 156 | $section_label = $this->addControlSection( |
| 157 | 'evf-label', |
| 158 | __( 'Labels', 'everest-forms' ), |
| 159 | 'assets/icon.png', |
| 160 | $this |
| 161 | ); |
| 162 | |
| 163 | $selector = '.evf-field-label'; |
| 164 | $section_label->typographySection( __( 'Typography', 'everest-forms' ), $selector, $this ); |
| 165 | $section_label->addStyleControls( |
| 166 | array( |
| 167 | array( |
| 168 | 'name' => __( 'Text Color', 'everest-forms' ), |
| 169 | 'selector' => $selector, |
| 170 | 'property' => 'color', |
| 171 | ), |
| 172 | ) |
| 173 | ); |
| 174 | $section_label->addStyleControl( |
| 175 | array( |
| 176 | 'name' => __( 'Asterisk Color', 'everest-forms' ), |
| 177 | 'selector' => '.evf-field-label .required', |
| 178 | 'property' => 'color', |
| 179 | ) |
| 180 | ); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Submit button style. |
| 185 | * |
| 186 | * @since 3.0.5 |
| 187 | */ |
| 188 | public function submit_btn_style() { |
| 189 | $section_submit_btn = $this->addControlSection( |
| 190 | 'evf-submit-button', |
| 191 | __( 'Submit Button', 'everest-forms' ), |
| 192 | 'assets/icon.png', |
| 193 | $this |
| 194 | ); |
| 195 | |
| 196 | $selector_submit_bttn = '.everest-forms-submit-button'; |
| 197 | $section_submit_btn->addStyleControls( |
| 198 | array( |
| 199 | array( |
| 200 | 'name' => __( 'Color', 'everest-forms' ), |
| 201 | 'selector' => $selector_submit_bttn, |
| 202 | 'property' => 'color', |
| 203 | ), |
| 204 | array( |
| 205 | 'name' => __( 'Background Color', 'everest-forms' ), |
| 206 | 'selector' => $selector_submit_bttn, |
| 207 | 'property' => 'background-color', |
| 208 | ), |
| 209 | array( |
| 210 | 'name' => __( 'Hover Color', 'everest-forms' ), |
| 211 | 'selector' => '.ff-btn-submit:hover', |
| 212 | 'property' => 'background-color', |
| 213 | ), |
| 214 | array( |
| 215 | 'name' => __( 'Width', 'everest-forms' ), |
| 216 | 'selector' => $selector_submit_bttn, |
| 217 | 'property' => 'width', |
| 218 | 'control_type' => 'slider-measurebox', |
| 219 | 'unit' => 'px', |
| 220 | ), |
| 221 | array( |
| 222 | 'name' => __( 'Margin Top', 'everest-forms' ), |
| 223 | 'selector' => $selector_submit_bttn, |
| 224 | 'property' => 'margin-top', |
| 225 | 'control_type' => 'slider-measurebox', |
| 226 | 'unit' => 'px', |
| 227 | ), |
| 228 | ) |
| 229 | ); |
| 230 | |
| 231 | $section_submit_btn->addPreset( |
| 232 | 'padding', |
| 233 | 'evf_submit_bttn_padding', |
| 234 | __( 'Padding', 'everest-forms' ), |
| 235 | $selector_submit_bttn |
| 236 | )->whiteList(); |
| 237 | |
| 238 | $section_submit_btn->addPreset( |
| 239 | 'margin', |
| 240 | 'evf_submit_bttn_margin', |
| 241 | __( 'Margin', 'everest-forms' ), |
| 242 | $selector_submit_bttn |
| 243 | )->whiteList(); |
| 244 | |
| 245 | $section_submit_btn->typographySection( __( 'Typography', 'everest-forms' ), $selector_submit_bttn, $this ); |
| 246 | $section_submit_btn->borderSection( __( 'Border', 'everest-forms' ), $selector_submit_bttn, $this ); |
| 247 | $section_submit_btn->borderSection( __( 'Hover Border', 'everest-forms' ), $selector_submit_bttn . ':hover', $this ); |
| 248 | $section_submit_btn->boxShadowSection( __( 'Box Shadow', 'everest-forms' ), $selector_submit_bttn, $this ); |
| 249 | $section_submit_btn->boxShadowSection( __( 'Hover Box Shadow', 'everest-forms' ), $selector_submit_bttn . ':hover', $this ); |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Render the element's UI by outputting HTML. |
| 254 | * |
| 255 | * @since 3.0.5 |
| 256 | * |
| 257 | * @param array $options |
| 258 | * @param array $defaults |
| 259 | * @param mixed $content |
| 260 | */ |
| 261 | public function render( $options, $defaults, $content ) { |
| 262 | |
| 263 | $content = sprintf( '<div class="evf-widget">%s</div>', esc_html__( 'Everest Forms', 'everest-forms' ) ); |
| 264 | |
| 265 | if ( ! isset( $options['evf_form'] ) || empty( $options['evf_form'] ) ) { |
| 266 | |
| 267 | echo wp_kses( $content, evf_get_allowed_html_tags( 'builder' ) ); |
| 268 | |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | $form_id = absint( $options['evf_form'] ); |
| 273 | |
| 274 | if ( empty( $form_id ) ) { |
| 275 | |
| 276 | echo wp_kses( $content, evf_get_allowed_html_tags( 'builder' ) ); |
| 277 | |
| 278 | return; |
| 279 | } |
| 280 | |
| 281 | // Getting the form. |
| 282 | $content = \EVF_Shortcodes::shortcode_wrapper( |
| 283 | array( 'EVF_Shortcode_Form', 'output' ), |
| 284 | array( |
| 285 | 'id' => $form_id, |
| 286 | ), |
| 287 | array( 'class' => 'everest-forms' ) |
| 288 | ); |
| 289 | |
| 290 | echo wp_kses( $content, evf_get_allowed_html_tags( 'builder' ) ); |
| 291 | } |
| 292 | } |
| 293 |