PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.50
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.50
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / FormBuilder / Components / Checkable.php

Checkable.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 3.6.50, at app/Services/FormBuilder/Components/Checkable.php

113 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services\FormBuilder\Components;
4
5 use FluentForm\App\Helpers\Helper;
6 use FluentForm\App\Modules\Component\Component;
7 use FluentForm\Framework\Helpers\ArrayHelper;
8
9 class Checkable extends BaseComponent
10 {
11 /**
12 * Compile and echo the html element
13 * @param array $data [element data]
14 * @param stdClass $form [Form Object]
15 * @return viod
16 */
17 public function compile($data, $form)
18 {
19 $elementName = $data['element'];
20
21 $data = apply_filters('fluenform_rendering_field_data_'.$elementName, $data, $form);
22
23 $data['attributes']['class'] = trim(
24 'ff-el-form-check-input ' .
25 'ff-el-form-check-'.$data['attributes']['type'].' '.
26 ArrayHelper::get($data, 'attributes.class')
27 );
28
29 if ($data['attributes']['type'] == 'checkbox') {
30 $data['attributes']['name'] = $data['attributes']['name'] . '[]';
31 }
32
33 $defaultValues = (array)$this->extractValueFromAttributes($data);
34
35 if($dynamicValues = $this->extractDynamicValues($data, $form)) {
36 $defaultValues = $dynamicValues;
37 }
38
39 $elMarkup = '';
40
41 $firstTabIndex = \FluentForm\App\Helpers\Helper::getNextTabIndex();
42
43 if(!$formattedOptions = ArrayHelper::get($data, 'settings.advanced_options')) {
44 $options = ArrayHelper::get($data, 'options', []);
45 $formattedOptions = [];
46 foreach($options as $value => $label) {
47 $formattedOptions[] = [
48 'label' => $label,
49 'value' => $value,
50 'calc_value' => '',
51 'image' => ''
52 ];
53 }
54 }
55
56 $hasImageOption = ArrayHelper::get($data, 'settings.enable_image_input');
57
58 if($hasImageOption) {
59 $data['settings']['container_class'] .= '';
60 $elMarkup .= '<div class="ff_el_checkable_photo_holders">';
61 }
62
63 $data['settings']['container_class'] .= ' '.ArrayHelper::get($data, 'settings.layout_class');
64
65 foreach ($formattedOptions as $option) {
66
67 $displayType = isset($data['settings']['display_type']) ? ' ff-el-form-check-' . $data['settings']['display_type'] : '';
68 $parentClass = "ff-el-form-check{$displayType}";
69
70 if (in_array($option['value'], $defaultValues)) {
71 $data['attributes']['checked'] = true;
72 $parentClass .= ' ff_item_selected';
73 } else {
74 $data['attributes']['checked'] = false;
75 }
76
77 if($firstTabIndex) {
78 $data['attributes']['tabindex'] = $firstTabIndex;
79 $firstTabIndex = '-1';
80 }
81
82 $data['attributes']['value'] = $option['value'];
83 $data['attributes']['data-calc_value'] = ArrayHelper::get($option,'calc_value');
84
85 $atts = $this->buildAttributes($data['attributes']);
86
87
88 $id = $this->getUniqueid(str_replace(['[', ']'], ['', ''], $data['attributes']['name']));
89
90
91 if($hasImageOption) {
92 $parentClass .= ' ff-el-image-holder';
93 }
94
95 $elMarkup .= "<div class='{$parentClass}'>";
96 // Here we can push the visual items
97 if($hasImageOption) {
98 $elMarkup .= "<label style='background-image: url({$option['image']})' class='ff-el-image-input-src' for={$id}></label>";
99 }
100
101 $elMarkup .= "<label class='ff-el-form-check-label' for={$id}><input {$atts} id='{$id}'> <span>{$option['label']}</span></label>";
102 $elMarkup .= "</div>";
103 }
104
105
106 if($hasImageOption) {
107 $elMarkup .= '</div>';
108 }
109
110 $html = $this->buildElementMarkup($elMarkup, $data, $form);
111 echo apply_filters('fluenform_rendering_field_html_'.$elementName, $html, $data, $form);
112 }
113 }