PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.2
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.2
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 / Rating.php

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

92 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\Framework\Helpers\ArrayHelper;
7
8 class Rating extends BaseComponent
9 {
10 /**
11 * Compile and echo the html element
12 *
13 * @param array $data [element data]
14 * @param \stdClass $form [Form Object]
15 *
16 * @return void
17 */
18 public function compile($data, $form)
19 {
20 $elementName = $data['element'];
21
22 $data = apply_filters_deprecated(
23 'fluentform_rendering_field_data_' . $elementName,
24 [
25 $data,
26 $form
27 ],
28 FLUENTFORM_FRAMEWORK_UPGRADE,
29 'fluentform/rendering_field_data_' . $elementName,
30 'Use fluentform/rendering_field_data_' . $elementName . ' instead of fluentform_rendering_field_data_' . $elementName
31 );
32
33 $data = apply_filters('fluentform/rendering_field_data_' . $elementName, $data, $form);
34
35 $data['attributes']['type'] = 'radio';
36
37 $defaultValues = (array) $this->extractValueFromAttributes($data);
38
39 $elMarkup = "<div class='ff-el-ratings jss-ff-el-ratings' role='radiogroup'>";
40 $ratingText = '';
41
42 foreach ($data['options'] as $value => $label) {
43 $starred = '';
44 if (in_array($value, $defaultValues)) {
45 $data['attributes']['checked'] = true;
46 $starred = 'active';
47 } else {
48 $data['attributes']['checked'] = false;
49 }
50
51 if ($tabIndex = Helper::getNextTabIndex()) {
52 $data['attributes']['tabindex'] = $tabIndex;
53 }
54
55 $atts = $this->buildAttributes($data['attributes']);
56 $id = esc_attr($this->getUniqueid(str_replace(['[', ']'], ['', ''], $data['attributes']['name'])));
57
58 $ariaRequired = 'false';
59 if (ArrayHelper::get($data, 'settings.validation_rules.required.value')) {
60 $ariaRequired = 'true';
61 }
62
63 $elMarkup .= "<label for={$id} class='{$starred}'><input {$atts} id={$id} aria-valuenow='" . esc_attr($value) . "' value='" . esc_attr($value) . "' aria-required={$ariaRequired} aria-invalid='false'>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $starred, $atts, $id are escaped before being passed in.
64 $elMarkup .= '<?xml version="1.0" encoding="iso-8859-1"?><svg class="jss-ff-svg ff-svg" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 53.867 53.867" style="enable-background:new 0 0 53.867 53.867;" xml:space="preserve"><polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g></svg>';
65 $elMarkup .= '</label>';
66
67 if ('yes' == ArrayHelper::get($data, 'settings.show_text')) {
68 $displayDefaultText = in_array($value, $defaultValues) ? 'display: inline-block' : 'display: none';
69 $ratingText .= "<span style='{$displayDefaultText}' class='ff-el-rating-text' data-id='{$id}'>" . fluentform_sanitize_html($label) . '</span>';
70 }
71 };
72
73 $elMarkup .= '</div>' . $ratingText;
74
75 $html = $this->buildElementMarkup($elMarkup, $data, $form);
76
77 $html = apply_filters_deprecated(
78 'fluentform_rendering_field_html_' . $elementName,
79 [
80 $html,
81 $data,
82 $form
83 ],
84 FLUENTFORM_FRAMEWORK_UPGRADE,
85 'fluentform/rendering_field_html_' . $elementName,
86 'Use fluentform/rendering_field_html_' . $elementName . ' instead of fluentform_rendering_field_html_' . $elementName
87 );
88
89 $this->printContent('fluentform/rendering_field_html_' . $elementName, $html, $data, $form);
90 }
91 }
92