PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.64
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.64
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.64, at app/Services/FormBuilder/Components/Checkable.php

117 lines 3.9 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 if(ArrayHelper::get($data, 'settings.randomize_options') == 'yes') {
66 shuffle($formattedOptions);
67 }
68
69 foreach ($formattedOptions as $option) {
70
71 $displayType = isset($data['settings']['display_type']) ? ' ff-el-form-check-' . $data['settings']['display_type'] : '';
72 $parentClass = "ff-el-form-check{$displayType}";
73
74 if (in_array($option['value'], $defaultValues)) {
75 $data['attributes']['checked'] = true;
76 $parentClass .= ' ff_item_selected';
77 } else {
78 $data['attributes']['checked'] = false;
79 }
80
81 if($firstTabIndex) {
82 $data['attributes']['tabindex'] = $firstTabIndex;
83 $firstTabIndex = '-1';
84 }
85
86 $data['attributes']['value'] = $option['value'];
87 $data['attributes']['data-calc_value'] = ArrayHelper::get($option,'calc_value');
88
89 $atts = $this->buildAttributes($data['attributes']);
90
91
92 $id = $this->getUniqueid(str_replace(['[', ']'], ['', ''], $data['attributes']['name']));
93
94
95 if($hasImageOption) {
96 $parentClass .= ' ff-el-image-holder';
97 }
98
99 $elMarkup .= "<div class='{$parentClass}'>";
100 // Here we can push the visual items
101 if($hasImageOption) {
102 $elMarkup .= "<label style='background-image: url({$option['image']})' class='ff-el-image-input-src' for={$id}></label>";
103 }
104
105 $elMarkup .= "<label class='ff-el-form-check-label' for={$id}><input {$atts} id='{$id}'> <span>{$option['label']}</span></label>";
106 $elMarkup .= "</div>";
107 }
108
109
110 if($hasImageOption) {
111 $elMarkup .= '</div>';
112 }
113
114 $html = $this->buildElementMarkup($elMarkup, $data, $form);
115 echo apply_filters('fluenform_rendering_field_html_'.$elementName, $html, $data, $form);
116 }
117 }