← All changes
|
app/Services/FormBuilder/Components/TermsAndConditions.php
+71
-16
3.6.22
→
6.2.15
View file →
| @@ -1,20 +1,35 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentForm\App\Services\FormBuilder\Components; |
| 4 | 4 | |
| 5 | +use FluentForm\App\Helpers\Helper; | |
| 6 | +use FluentForm\Framework\Helpers\ArrayHelper; | |
| 7 | + | |
| 5 | 8 | class TermsAndConditions extends BaseComponent |
| 6 | 9 | { |
| 7 | 10 | /** |
| 8 | 11 | * Compile and echo the html element |
| 9 | - * @param array $data [element data] | |
| 10 | - * @param stdClass $form [Form Object] | |
| 11 | - * @return viod | |
| 12 | + * | |
| 13 | + * @param array $data [element data] | |
| 14 | + * @param \stdClass $form [Form Object] | |
| 15 | + * | |
| 16 | + * @return void | |
| 12 | 17 | */ |
| 13 | 18 | public function compile($data, $form) |
| 14 | 19 | { |
| 15 | 20 | $elementName = $data['element']; |
| 16 | - $data = apply_filters('fluenform_rendering_field_data_' . $elementName, $data, $form); | |
| 21 | + $data = apply_filters_deprecated( | |
| 22 | + 'fluentform_rendering_field_data_' . $elementName, | |
| 23 | + [ | |
| 24 | + $data, | |
| 25 | + $form | |
| 26 | + ], | |
| 27 | + FLUENTFORM_FRAMEWORK_UPGRADE, | |
| 28 | + 'fluentform/rendering_field_data_' . $elementName, | |
| 29 | + 'Use fluentform/rendering_field_data_' . $elementName . ' instead of fluentform_rendering_field_data_' . $elementName | |
| 30 | + ); | |
| 31 | + $data = apply_filters('fluentform/rendering_field_data_' . $elementName, $data, $form); | |
| 17 | 32 | |
| 18 | 33 | $hasConditions = $this->hasConditions($data) ? 'has-conditions ' : ''; |
| 19 | 34 | |
| 20 | 35 | $cls = trim( |
| @@ -20,35 +35,75 @@ | ||
| 20 | 35 | $cls = trim( |
| 21 | 36 | $this->getDefaultContainerClass() |
| 22 | 37 | . ' ' . @$data['settings']['container_class'] |
| 23 | 38 | . ' ' . $hasConditions |
| 24 | - .' ff-el-input--content' | |
| 39 | + . ' ff-el-input--content' | |
| 25 | 40 | ); |
| 26 | 41 | |
| 27 | 42 | $uniqueId = $this->getUniqueId($data['attributes']['name']); |
| 43 | + $escapedUniqueId = esc_attr($uniqueId); | |
| 28 | 44 | |
| 29 | 45 | $data['attributes']['id'] = $uniqueId; |
| 30 | 46 | $data['attributes']['class'] = trim( |
| 31 | 47 | 'ff-el-form-check-input ' . |
| 32 | - $data['attributes']['class'] | |
| 48 | + ArrayHelper::get($data, 'attributes.class', '') | |
| 33 | 49 | ); |
| 34 | 50 | |
| 35 | - if($tabIndex = \FluentForm\App\Helpers\Helper::getNextTabIndex()) { | |
| 51 | + if ($tabIndex = Helper::getNextTabIndex()) { | |
| 36 | 52 | $data['attributes']['tabindex'] = $tabIndex; |
| 37 | 53 | } |
| 38 | 54 | |
| 39 | 55 | $atts = $this->buildAttributes($data['attributes']); |
| 40 | 56 | $checkbox = ''; |
| 57 | + | |
| 58 | + $ariaRequired = 'false'; | |
| 59 | + if (ArrayHelper::get($data, 'settings.validation_rules.required.value')) { | |
| 60 | + $ariaRequired = 'true'; | |
| 61 | + } | |
| 62 | + | |
| 41 | 63 | if ($data['settings']['has_checkbox']) { |
| 42 | - $checkbox = "<span class='ff_tc_checkbox'><input {$atts} value='on'></span>"; | |
| 64 | + $checkbox = "<span class='ff_tc_checkbox'><input {$atts} value='on' aria-invalid='false' aria-required={$ariaRequired}></span>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts is escaped before being passed in. | |
| 43 | 65 | } |
| 66 | + | |
| 67 | + $link_count = substr_count($data['settings']['tnc_html'], '<a '); | |
| 68 | + if($link_count > 0){ | |
| 69 | + $ariaLabel = sprintf( | |
| 70 | + /* translators: 1: Terms title or HTML label, 2: Number of links in the terms text. */ | |
| 71 | + esc_html(_n( | |
| 72 | + 'Terms and Conditions: %1$s Contains %2$d link. Use tab navigation to review.', | |
| 73 | + 'Terms and Conditions: %1$s Contains %2$d links. Use tab navigation to review.', | |
| 74 | + $link_count, | |
| 75 | + 'fluentform' | |
| 76 | + )), | |
| 77 | + $data['settings']['tnc_html'], | |
| 78 | + $link_count | |
| 79 | + ); | |
| 80 | + }else{ | |
| 81 | + $ariaLabel = wp_strip_all_tags($data['settings']['tnc_html']); | |
| 82 | + } | |
| 83 | + | |
| 84 | + | |
| 85 | + $ariaLabel = wp_strip_all_tags($ariaLabel); | |
| 86 | + $ariaLabel = esc_attr($ariaLabel); | |
| 87 | + $html = "<div class='" . esc_attr($cls) . "'>"; | |
| 88 | + $html .= "<div class='ff-el-form-check ff-el-tc'>"; | |
| 89 | + $html .= "<label aria-label='{$ariaLabel}' class='ff-el-form-check-label ff_tc_label' for='{$escapedUniqueId}'>"; | |
| 90 | + $html .= "{$checkbox} <div class='ff_t_c'>" . fluentform_sanitize_html($data['settings']['tnc_html']) . '</div>'; | |
| 91 | + $html .= '</label>'; | |
| 92 | + $html .= '</div>'; | |
| 93 | + $html .= '</div>'; | |
| 94 | + | |
| 95 | + $html = apply_filters_deprecated( | |
| 96 | + 'fluentform_rendering_field_html_' . $elementName, | |
| 97 | + [ | |
| 98 | + $html, | |
| 99 | + $data, | |
| 100 | + $form | |
| 101 | + ], | |
| 102 | + FLUENTFORM_FRAMEWORK_UPGRADE, | |
| 103 | + 'fluentform/rendering_field_html_' . $elementName, | |
| 104 | + 'Use fluentform/rendering_field_html_' . $elementName . ' instead of fluentform_rendering_field_html_' . $elementName | |
| 105 | + ); | |
| 44 | 106 | |
| 45 | - $html = "<div class='{$cls}'>"; | |
| 46 | - $html .= "<div class='ff-el-form-check ff-el-tc'>"; | |
| 47 | - $html .= "<label class='ff-el-form-check-label ff_tc_label' for={$uniqueId}>"; | |
| 48 | - $html .= "{$checkbox} <div class='ff_t_c'>{$data['settings']['tnc_html']}</div>"; | |
| 49 | - $html .= "</label>"; | |
| 50 | - $html .= "</div>"; | |
| 51 | - $html .= "</div>"; | |
| 52 | - echo apply_filters('fluenform_rendering_field_html_'.$elementName, $html, $data, $form); | |
| 107 | + $this->printContent('fluentform/rendering_field_html_' . $elementName, $html, $data, $form); | |
| 53 | 108 | } |
| 54 | 109 | } |