| @@ -1,29 +1,44 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentForm\App\Services\FormBuilder\Components; |
| 4 | 4 | |
| 5 | +use FluentForm\App\Services\FormBuilder\AutocompleteTokens; | |
| 5 | 6 | use FluentForm\App\Helpers\Helper; |
| 6 | 7 | use FluentForm\Framework\Helpers\ArrayHelper; |
| 8 | +use FluentForm\App\Services\FormBuilder\Components\Select; | |
| 7 | 9 | |
| 8 | -class Name extends BaseComponent | |
| 10 | +class Name extends Select | |
| 9 | 11 | { |
| 10 | 12 | /** |
| 11 | 13 | * Compile and echo the html element |
| 12 | - * @param array $data [element data] | |
| 13 | - * @param stdClass $form [Form Object] | |
| 14 | - * @return viod | |
| 14 | + * | |
| 15 | + * @param array $data [element data] | |
| 16 | + * @param \stdClass $form [Form Object] | |
| 17 | + * | |
| 18 | + * @return void | |
| 15 | 19 | */ |
| 16 | 20 | public function compile($data, $form) |
| 17 | 21 | { |
| 18 | 22 | $elementName = $data['element']; |
| 19 | 23 | |
| 20 | - $data = apply_filters('fluenform_rendering_field_data_'.$elementName, $data, $form); | |
| 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 | + ); | |
| 21 | 34 | |
| 35 | + $data = apply_filters('fluentform/rendering_field_data_' . $elementName, $data, $form); | |
| 36 | + | |
| 22 | 37 | $rootName = $data['attributes']['name']; |
| 23 | 38 | |
| 24 | 39 | $hasConditions = $this->hasConditions($data) ? 'has-conditions ' : ''; |
| 25 | - | |
| 40 | + | |
| 26 | 41 | if (empty($data['attributes']['class'])) { |
| 27 | 42 | $data['attributes']['class'] = ''; |
| 28 | 43 | } |
| 29 | 44 | |
| @@ -28,23 +43,24 @@ | ||
| 28 | 43 | } |
| 29 | 44 | |
| 30 | 45 | $data['attributes']['class'] .= $hasConditions; |
| 31 | 46 | $data['attributes']['class'] .= ' ff-field_container ff-name-field-wrapper'; |
| 32 | - if($containerClass = ArrayHelper::get($data, 'settings.container_class')) { | |
| 33 | - $data['attributes']['class'] .= ' '.$containerClass; | |
| 47 | + if ($containerClass = ArrayHelper::get($data, 'settings.container_class')) { | |
| 48 | + $data['attributes']['class'] .= ' ' . $containerClass; | |
| 34 | 49 | } |
| 50 | + // autocomplete belongs to the sub-fields, not to this wrapper <div>. | |
| 35 | 51 | $atts = $this->buildAttributes( |
| 36 | - ArrayHelper::except($data['attributes'], 'name') | |
| 52 | + ArrayHelper::except($data['attributes'], ['name', 'autocomplete']) | |
| 37 | 53 | ); |
| 38 | 54 | |
| 39 | - $html = "<div {$atts}>"; | |
| 55 | + $html = "<div {$atts}>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts is escaped before being passed in. | |
| 40 | 56 | $html .= "<div class='ff-t-container'>"; |
| 41 | 57 | |
| 42 | 58 | $labelPlacement = ArrayHelper::get($data, 'settings.label_placement'); |
| 43 | 59 | $labelPlacementClass = ''; |
| 44 | - | |
| 60 | + | |
| 45 | 61 | if ($labelPlacement) { |
| 46 | - $labelPlacementClass = ' ff-el-form-'.$labelPlacement; | |
| 62 | + $labelPlacementClass = ' ff-el-form-' . $labelPlacement; | |
| 47 | 63 | } |
| 48 | 64 | |
| 49 | 65 | foreach ($data['fields'] as $field) { |
| 50 | 66 | if ($field['settings']['visible']) { |
| @@ -49,29 +65,67 @@ | ||
| 49 | 65 | foreach ($data['fields'] as $field) { |
| 50 | 66 | if ($field['settings']['visible']) { |
| 51 | 67 | $fieldName = $field['attributes']['name']; |
| 52 | 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 | + ); | |
| 53 | 75 | @$field['attributes']['class'] = trim( |
| 54 | 76 | 'ff-el-form-control ' . |
| 55 | 77 | $field['attributes']['class'] |
| 56 | 78 | ); |
| 57 | 79 | |
| 58 | - if ($tabIndex = \FluentForm\App\Helpers\Helper::getNextTabIndex()) { | |
| 80 | + if ($tabIndex = Helper::getNextTabIndex()) { | |
| 59 | 81 | $field['attributes']['tabindex'] = $tabIndex; |
| 60 | 82 | } |
| 61 | 83 | |
| 62 | - | |
| 63 | 84 | @$field['settings']['container_class'] .= $labelPlacementClass; |
| 64 | 85 | |
| 65 | 86 | $field['attributes']['id'] = $this->makeElementId($field, $form); |
| 87 | + $nameTitleClass = ''; | |
| 88 | + $atts = $this->buildAttributes($field['attributes']); | |
| 66 | 89 | |
| 67 | - $elMarkup = "<input ".$this->buildAttributes($field['attributes']).">"; | |
| 90 | + $ariaRequired = 'false'; | |
| 91 | + if (ArrayHelper::get($field, 'settings.validation_rules.required.value')) { | |
| 92 | + $ariaRequired = 'true'; | |
| 93 | + } | |
| 68 | 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 | + | |
| 69 | 110 | $inputTextMarkup = $this->buildElementMarkup($elMarkup, $field, $form); |
| 70 | - $html .= "<div class='ff-t-cell'>{$inputTextMarkup}</div>"; | |
| 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. | |
| 71 | 112 | } |
| 72 | 113 | } |
| 73 | - $html .= "</div>"; | |
| 74 | - $html .= "</div>"; | |
| 75 | - echo apply_filters('fluenform_rendering_field_html_'.$elementName, $html, $data, $form); | |
| 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); | |
| 76 | 130 | } |
| 77 | 131 | } |