| 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 Name extends BaseComponent |
| 9 |
{ |
| 10 |
/** |
| 11 |
* Compile and echo the html element |
| 12 |
* @param array $data [element data] |
| 13 |
* @param stdClass $form [Form Object] |
| 14 |
* @return viod |
| 15 |
*/ |
| 16 |
public function compile($data, $form) |
| 17 |
{ |
| 18 |
$elementName = $data['element']; |
| 19 |
|
| 20 |
$data = apply_filters('fluenform_rendering_field_data_'.$elementName, $data, $form); |
| 21 |
|
| 22 |
$rootName = $data['attributes']['name']; |
| 23 |
|
| 24 |
$hasConditions = $this->hasConditions($data) ? 'has-conditions ' : ''; |
| 25 |
|
| 26 |
if (empty($data['attributes']['class'])) { |
| 27 |
$data['attributes']['class'] = ''; |
| 28 |
} |
| 29 |
|
| 30 |
$data['attributes']['class'] .= $hasConditions; |
| 31 |
$data['attributes']['class'] .= ' ff-field_container ff-name-field-wrapper'; |
| 32 |
if($containerClass = ArrayHelper::get($data, 'settings.container_class')) { |
| 33 |
$data['attributes']['class'] .= ' '.$containerClass; |
| 34 |
} |
| 35 |
$atts = $this->buildAttributes( |
| 36 |
ArrayHelper::except($data['attributes'], 'name') |
| 37 |
); |
| 38 |
|
| 39 |
$html = "<div {$atts}>"; |
| 40 |
$html .= "<div class='ff-t-container'>"; |
| 41 |
|
| 42 |
$labelPlacement = ArrayHelper::get($data, 'settings.label_placement'); |
| 43 |
$labelPlacementClass = ''; |
| 44 |
|
| 45 |
if ($labelPlacement) { |
| 46 |
$labelPlacementClass = ' ff-el-form-'.$labelPlacement; |
| 47 |
} |
| 48 |
|
| 49 |
foreach ($data['fields'] as $field) { |
| 50 |
if ($field['settings']['visible']) { |
| 51 |
$fieldName = $field['attributes']['name']; |
| 52 |
$field['attributes']['name'] = $rootName . '[' . $fieldName . ']'; |
| 53 |
@$field['attributes']['class'] = trim( |
| 54 |
'ff-el-form-control ' . |
| 55 |
$field['attributes']['class'] |
| 56 |
); |
| 57 |
|
| 58 |
if ($tabIndex = \FluentForm\App\Helpers\Helper::getNextTabIndex()) { |
| 59 |
$field['attributes']['tabindex'] = $tabIndex; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
@$field['settings']['container_class'] .= $labelPlacementClass; |
| 64 |
|
| 65 |
$field['attributes']['id'] = $this->makeElementId($field, $form); |
| 66 |
|
| 67 |
$elMarkup = "<input ".$this->buildAttributes($field['attributes']).">"; |
| 68 |
|
| 69 |
$inputTextMarkup = $this->buildElementMarkup($elMarkup, $field, $form); |
| 70 |
$html .= "<div class='ff-t-cell'>{$inputTextMarkup}</div>"; |
| 71 |
} |
| 72 |
} |
| 73 |
$html .= "</div>"; |
| 74 |
$html .= "</div>"; |
| 75 |
echo apply_filters('fluenform_rendering_field_html_'.$elementName, $html, $data, $form); |
| 76 |
} |
| 77 |
} |
| 78 |
|