PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / trunk
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder vtrunk
6.2.15 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 All 197 releases
fluentform / app / Services / FormBuilder / Components / Name.php

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

132 lines 5.3 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\Services\FormBuilder\AutocompleteTokens;
6 use FluentForm\App\Helpers\Helper;
7 use FluentForm\Framework\Helpers\ArrayHelper;
8 use FluentForm\App\Services\FormBuilder\Components\Select;
9
10 class Name extends Select
11 {
12 /**
13 * Compile and echo the html element
14 *
15 * @param array $data [element data]
16 * @param \stdClass $form [Form Object]
17 *
18 * @return void
19 */
20 public function compile($data, $form)
21 {
22 $elementName = $data['element'];
23
24 $data = apply_filters_deprecated(
25 'fluentform_rendering_field_data_' . $elementName,
26 [
27 $data,
28 $form
29 ],
30 FLUENTFORM_FRAMEWORK_UPGRADE,
31 'fluentform/rendering_field_data_' . $elementName,
32 'Use fluentform/rendering_field_data_' . $elementName . ' instead of fluentform_rendering_field_data_' . $elementName
33 );
34
35 $data = apply_filters('fluentform/rendering_field_data_' . $elementName, $data, $form);
36
37 $rootName = $data['attributes']['name'];
38
39 $hasConditions = $this->hasConditions($data) ? 'has-conditions ' : '';
40
41 if (empty($data['attributes']['class'])) {
42 $data['attributes']['class'] = '';
43 }
44
45 $data['attributes']['class'] .= $hasConditions;
46 $data['attributes']['class'] .= ' ff-field_container ff-name-field-wrapper';
47 if ($containerClass = ArrayHelper::get($data, 'settings.container_class')) {
48 $data['attributes']['class'] .= ' ' . $containerClass;
49 }
50 // autocomplete belongs to the sub-fields, not to this wrapper <div>.
51 $atts = $this->buildAttributes(
52 ArrayHelper::except($data['attributes'], ['name', 'autocomplete'])
53 );
54
55 $html = "<div {$atts}>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts is escaped before being passed in.
56 $html .= "<div class='ff-t-container'>";
57
58 $labelPlacement = ArrayHelper::get($data, 'settings.label_placement');
59 $labelPlacementClass = '';
60
61 if ($labelPlacement) {
62 $labelPlacementClass = ' ff-el-form-' . $labelPlacement;
63 }
64
65 foreach ($data['fields'] as $field) {
66 if ($field['settings']['visible']) {
67 $fieldName = $field['attributes']['name'];
68 $field['attributes']['name'] = $rootName . '[' . $fieldName . ']';
69
70 $field['attributes']['autocomplete'] = AutocompleteTokens::forSubField(
71 $fieldName,
72 ArrayHelper::get($data, 'attributes.autocomplete'),
73 ArrayHelper::get($field, 'attributes.autocomplete')
74 );
75 @$field['attributes']['class'] = trim(
76 'ff-el-form-control ' .
77 $field['attributes']['class']
78 );
79
80 if ($tabIndex = Helper::getNextTabIndex()) {
81 $field['attributes']['tabindex'] = $tabIndex;
82 }
83
84 @$field['settings']['container_class'] .= $labelPlacementClass;
85
86 $field['attributes']['id'] = $this->makeElementId($field, $form);
87 $nameTitleClass = '';
88 $atts = $this->buildAttributes($field['attributes']);
89
90 $ariaRequired = 'false';
91 if (ArrayHelper::get($field, 'settings.validation_rules.required.value')) {
92 $ariaRequired = 'true';
93 }
94
95 if ('select' == $field['attributes']['type']) {
96 if (! defined('FLUENTFORMPRO')) {
97 continue;
98 }
99 $nameTitleClass = ' ff-name-title';
100
101 $defaultValues = (array) $this->extractValueFromAttributes($field);
102
103 $options = $this->buildOptions($field, $defaultValues);
104
105 $elMarkup = '<select ' . $atts . '>' . $options . '</select>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts and $options are escaped before being passed in.
106 } else {
107 $elMarkup = '<input ' . $atts . 'aria-invalid="false" aria-required='.$ariaRequired.'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts is escaped before being passed in.
108 }
109
110 $inputTextMarkup = $this->buildElementMarkup($elMarkup, $field, $form);
111 $html .= "<div class='ff-t-cell " . esc_attr($nameTitleClass) . "'>{$inputTextMarkup}</div>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $inputTextMarkup is escaped before being passed in.
112 }
113 }
114 $html .= '</div>';
115 $html .= '</div>';
116
117 $html = apply_filters_deprecated(
118 'fluentform_rendering_field_html_' . $elementName,
119 [
120 $html,
121 $data,
122 $form
123 ],
124 FLUENTFORM_FRAMEWORK_UPGRADE,
125 'fluentform/rendering_field_html_' . $elementName,
126 'Use fluentform/rendering_field_html_' . $elementName . ' instead of fluentform_rendering_field_html_' . $elementName
127 );
128
129 $this->printContent('fluentform/rendering_field_html_' . $elementName, $html, $data, $form);
130 }
131 }
132