| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Services\FormBuilder\Components; |
| 4 |
|
| 5 |
class Address extends BaseComponent |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Wrapper class for address element |
| 9 |
* @var string |
| 10 |
*/ |
| 11 |
protected $wrapperClass = 'fluent-address'; |
| 12 |
|
| 13 |
/** |
| 14 |
* Compile and echo the html element |
| 15 |
* @param array $data [element data] |
| 16 |
* @param stdClass $form [Form Object] |
| 17 |
* @return viod |
| 18 |
*/ |
| 19 |
public function compile($data, $form) |
| 20 |
{ |
| 21 |
$elementName = $data['element']; |
| 22 |
$data = apply_filters('fluenform_rendering_field_data_'.$elementName, $data, $form); |
| 23 |
|
| 24 |
$rootName = $data['attributes']['name']; |
| 25 |
$hasConditions = $this->hasConditions($data) ? 'has-conditions ' : ''; |
| 26 |
$data['attributes']['class'] .= ' ff-name-address-wrapper ' . $this->wrapperClass . ' ' . $hasConditions; |
| 27 |
$data['attributes']['class'] = trim($data['attributes']['class']); |
| 28 |
$atts = $this->buildAttributes( |
| 29 |
\FluentForm\Framework\Helpers\ArrayHelper::except($data['attributes'], 'name') |
| 30 |
); |
| 31 |
ob_start(); |
| 32 |
echo "<div {$atts}>"; |
| 33 |
if($data['settings']['label']): |
| 34 |
echo "<div class='ff-el-input--label'>"; |
| 35 |
echo "<label>{$data['settings']['label']}</label>"; |
| 36 |
echo "</div>"; |
| 37 |
endif; |
| 38 |
echo "<div class='ff-el-input--content'>"; |
| 39 |
|
| 40 |
$visibleFields = array_chunk(array_filter($data['fields'], function($field) { |
| 41 |
return $field['settings']['visible']; |
| 42 |
}), 2); |
| 43 |
|
| 44 |
foreach ($visibleFields as $chunked) { |
| 45 |
echo "<div class='ff-t-container'>"; |
| 46 |
foreach ($chunked as $item) { |
| 47 |
if($item['settings']['visible']) { |
| 48 |
$itemName = $item['attributes']['name']; |
| 49 |
$item['attributes']['name'] = $rootName.'['.$itemName.']'; |
| 50 |
$item = apply_filters('fluentform_before_render_item', $item, $form); |
| 51 |
echo "<div class='ff-t-cell'>"; |
| 52 |
do_action('fluentform_render_item_'.$item['element'], $item, $form); |
| 53 |
echo "</div>"; |
| 54 |
} |
| 55 |
} |
| 56 |
echo "</div>"; |
| 57 |
} |
| 58 |
|
| 59 |
echo "</div>"; |
| 60 |
echo "</div>"; |
| 61 |
|
| 62 |
$html = ob_get_clean(); |
| 63 |
echo apply_filters('fluenform_rendering_field_html_'.$elementName, $html, $data, $form); |
| 64 |
} |
| 65 |
} |
| 66 |
|