60 lines
2.3 KiB
PHP
60 lines
2.3 KiB
PHP
|
|
<?php
|
||
|
|
/**
|
||
|
|
* @var \App\View\AppView $this
|
||
|
|
* @var \Cake\Datasource\EntityInterface $address
|
||
|
|
* @var \Cake\Collection\CollectionInterface|string[] $cities
|
||
|
|
* @var \Cake\Collection\CollectionInterface|string[] $states
|
||
|
|
* @var \Cake\Collection\CollectionInterface|string[] $countries
|
||
|
|
* @var string|null $prefix
|
||
|
|
*/
|
||
|
|
$prefix = $prefix ?? '';
|
||
|
|
$stateIdId = $prefix ? str_replace('.', '-', $prefix) . 'state_id' : 'state_id';
|
||
|
|
$inputs = [
|
||
|
|
$prefix ? $prefix . 'address_name' : 'address_name' => [],
|
||
|
|
$prefix ? $prefix . 'contact_name' : 'contact_name' => [],
|
||
|
|
$prefix ? $prefix . 'address_line1' : 'address_line1' => [],
|
||
|
|
$prefix ? $prefix . 'address_line2' : 'address_line2' => [],
|
||
|
|
$prefix ? $prefix . 'city' : 'city' => [],
|
||
|
|
$prefix ? $prefix . 'city_id' : 'city_id' => [
|
||
|
|
'hidden' => true,
|
||
|
|
'options' => $cities ?? [],
|
||
|
|
'empty' => true
|
||
|
|
],
|
||
|
|
$prefix ? $prefix . 'state_id' : 'state_id' => [
|
||
|
|
'options' => $states ?? [],
|
||
|
|
'id' => $stateIdId,
|
||
|
|
'empty' => 'Select a state',
|
||
|
|
'default' => $address->state_id ?? '',
|
||
|
|
'value' => $address->state_id ?? '',
|
||
|
|
],
|
||
|
|
$prefix ? $prefix . 'postal_code' : 'postal_code' => [],
|
||
|
|
$prefix ? $prefix . 'country_id' : 'country_id' => [
|
||
|
|
'options' => $countries,
|
||
|
|
'empty' => 'Select a country',
|
||
|
|
'default' => 233,
|
||
|
|
'hx-trigger' => isset($address->id) ? 'change' : 'change, load delay:1s',
|
||
|
|
'hx-get' => $this->Url->build([
|
||
|
|
'plugin' => 'CakeAddresses',
|
||
|
|
'controller' => 'States',
|
||
|
|
'action' => 'select',
|
||
|
|
'?' => [
|
||
|
|
'state_id' => $address->state_id ?? '',
|
||
|
|
],
|
||
|
|
]),
|
||
|
|
'hx-target' => '#' . $stateIdId,
|
||
|
|
// 'hx-indicator' => '.htmx-indicator',
|
||
|
|
],
|
||
|
|
$prefix ? $prefix . 'phone_number' : 'phone_number' => [],
|
||
|
|
$prefix ? $prefix . 'email' : 'email' => [],
|
||
|
|
$prefix ? $prefix . 'notes' : 'notes' => [],
|
||
|
|
];
|
||
|
|
foreach ($inputs as $inputName => $inputOptions) {
|
||
|
|
if (array_key_exists('hidden', $inputOptions) && $inputOptions['hidden']) {
|
||
|
|
echo $this->Form->hidden($inputName, $inputOptions);
|
||
|
|
}
|
||
|
|
if (!array_key_exists('hidden', $inputOptions) || !$inputOptions['hidden']) {
|
||
|
|
echo $this->Form->control($inputName, $inputOptions);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
?>
|