_fld = $field;
$this->_fk = $fk;
$this->_form_atomic_Cls_map = $form_atomic_Cls_map;
$this->_formID = $formID;
}
public function getCustomAttributes($element)
{
if ($this->property_exists_nested($this->_fld, "customAttributes->{$element}")) {
$attrString = '';
$customAttributs = $this->_fld->customAttributes->{$element};
foreach ($customAttributs as $attr) {
if (!isset($attr->key) || !EscapingHelper::isSafeAttributeKey((string) $attr->key)) {
continue;
}
$attrString .= " {$this->esc_attr($attr->key)}='{$this->esc_attr($attr->value)}'";
}
return $attrString;
}
return '';
}
public function getCustomClasses($element)
{
if ($this->property_exists_nested($this->_fld, "customClasses->{$element}")) {
return $this->esc_attr($this->_fld->customClasses->{$element});
}
return '';
}
public function renderHTMR($content)
{
$safeContent = Helpers::sanitizeUserHTML($content);
return $safeContent;
}
public function getAtomicCls($element)
{
$meaningfulElementClass = "bf-{$this->getMeaningfullElementClass($element)}";
if (empty($this->_fld) && empty($this->_fk)) {
if (is_object($this->_form_atomic_Cls_map) && property_exists($this->_form_atomic_Cls_map, ".$element")) {
$getAtomicCls = $this->_form_atomic_Cls_map->{".$element"};
return implode(' ', $getAtomicCls) . " {$element} {$meaningfulElementClass}";
}
return "$element {$meaningfulElementClass}";
}
if (isset($this->_fld->typ) && 'advanced-file-up' === $this->_fld->typ && isset($this->_form_atomic_Cls_map->{".$element"})) {
$getAtomicCls = $this->_form_atomic_Cls_map->{".$element"};
return implode(' ', $getAtomicCls) . " {$this->_fk}-{$element} {$meaningfulElementClass}";
}
$fieldElementCls = ".{$this->_fk}-{$element}";
$formId = explode('-', $this->_fk)[0]; // exmp: b12-10 => $formId = b12
// $formElementCls = ".{$element}-" . $formId;
$formElementCls = ".{$formId}-" . $element;
if (isset($this->_form_atomic_Cls_map->{$fieldElementCls})) {
$formElementAtomicClsString = '';
if (property_exists($this->_form_atomic_Cls_map, $formElementCls)) {
$formElementAtomicClsArray = $this->_form_atomic_Cls_map->{$formElementCls};
$formElementAtomicClsString = implode(' ', $formElementAtomicClsArray);
}
$getAtomicCls = $this->_form_atomic_Cls_map->{$fieldElementCls};
return implode(' ', $getAtomicCls) . " {$formElementAtomicClsString} {$this->_fk}-{$element} {$formId}-{$element} bf-{$element} {$meaningfulElementClass}";
}
return "{$this->_fk}-{$element} {$formId}-{$element} bf-{$element} {$meaningfulElementClass}";
}
public function getMeaningfullElementClass($element)
{
$elementTitleMap = [
'fld-wrp' => 'field-wrapper',
'lbl-wrp' => 'label-wrapper',
'lbl' => 'label',
'lbl-pre-i' => 'label-prefix-icon',
'lbl-suf-i' => 'label-suffix-icon',
'sub-titl' => 'subtitle',
'sub-titl-pre-i' => 'subtitle-prefix-icon',
'sub-titl-suf-i' => 'subtitle-suffix-icon',
'fld' => 'field',
'pre-i' => 'field-prefix-icon',
'suf-i' => 'field-suffix-icon',
'hlp-txt' => 'helper-text-container',
'hlp-txt-pre-i' => 'helper-text-prefix-icon',
'hlp-txt-suf-i' => 'helper-text-suffix-icon',
'err-msg' => 'error-messages-container',
'err-txt-pre-i' => 'error-text-prefix-icon',
'err-txt-suf-i' => 'error-text-suffix-icon',
'currency-fld-wrp' => 'currency-field-wrapper',
'btn' => 'button',
'btn-pre-i' => 'button-prefix-icon',
'btn-suf-i' => 'button-suffix-icon',
'other-inp' => 'other-option-input',
'inp-wrp' => 'input-wrapper',
'inp-wrp .filepond--panel-root' => 'item-panel-wrapper',
'inp-wrp .filepond--item-panel' => 'item-panel',
'inp-wrp .filepond--file-action-button' => 'file-action-button',
'inp-wrp .filepond--file' => 'file',
'inp-wrp .filepond--drop-label' => 'drop-label',
'inp-wrp .filepond--label-action' => 'label-action',
'option-list' => 'option-list',
'option-list .option' => 'option',
'option-list .opt-lbl-wrp' => 'option-label-container',
'option-list .opt-icn' => 'option-icon',
'option-list .opt-lbl' => 'option-label',
'option-list .opt-suffix' => 'option-suffix',
'option-list .opt-prefix' => 'option-prefix',
'divider' => 'divider',
'bx' => 'box',
'stripe-btn' => 'stripe-button',
'stripe-icn' => 'stripe-icon',
'stripe-pay-btn' => 'stripe-pay-button',
'rating-img' => 'rating-image',
'rating-msg' => 'rating-message',
'req-smbl' => 'asterisk-symbol',
'_frm-bg' => 'form-wrapper',
'_frm' => 'form-container',
];
if (isset($elementTitleMap[$element])) {
return $elementTitleMap[$element];
}
// Fallback: convert hyphenated element key to meaningful class
// e.g., 'fld-wrp' => 'fld wrp' => join with '-' after expanding abbreviations
$abbreviations = [
'fld' => 'field',
'wrp' => 'wrapper',
'lbl' => 'label',
'pre' => 'prefix',
'suf' => 'suffix',
'i' => 'icon',
'titl' => 'title',
'sub' => 'sub',
'hlp' => 'helper',
'txt' => 'text',
'err' => 'error',
'msg' => 'message',
'btn' => 'button',
'inp' => 'input',
'opt' => 'option',
'icn' => 'icon',
'img' => 'image',
'smbl' => 'symbol',
'req' => 'required',
'frm' => 'form',
'bg' => 'background',
];
$splitElements = explode('-', $element);
$meaningfulParts = [];
foreach ($splitElements as $part) {
$cleanPart = ltrim($part, '_');
$meaningfulParts[] = isset($abbreviations[$cleanPart]) ? $abbreviations[$cleanPart] : $cleanPart;
}
return implode('-', $meaningfulParts);
}
public function replaceToBackSlash($str)
{
$phReplaceToBackslash = str_replace('$_bf_$', '\\', $str); // Replace React inputs value "$_bf_$" to '\\'
return FieldValueHandler::replaceSmartTagWithValue($phReplaceToBackslash);
}
/**
* @param $element @exmp $element = 'fld-wrp'
*/
public function icon($icnPropName, $element)
{
$hasIconImg = $this->property_exists_nested($this->_fld, $icnPropName, '', 1);
$showPasswordIcon = $this->property_exists_nested($this->_fld, 'typ', 'password')
&& $this->property_exists_nested($this->_fld, 'config->showPasswordIcon', true);
// For password suffix, render a shared suffix wrapper that can contain both
// show/hide SVG and the configured suffix image (in this order).
if ('suf-i' === $element && ($hasIconImg || $showPasswordIcon)) {
$toggleButton = '';
$suffixIconImg = '';
if ($showPasswordIcon) {
$fieldKey = $this->esc_attr($this->_fk);
$toggleBtnId = "bf-pw-showhide-btn-{$fieldKey}";
$toggleSlashId = "bf-pw-eye-{$fieldKey}";
$toggleButton = '';
}
if ($hasIconImg) {
$suffixIconImg = 'getCustomAttributes($element)
. ' src="' . $this->esc_url($this->_fld->{$icnPropName}) . '"'
. ' alt=""'
. ' aria-hidden="true"'
. '/>';
}
if ($toggleButton) {
return '