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