2020-09-28 01:25:07 +02:00
|
|
|
<?php
|
|
|
|
if (is_array($fieldData)) {
|
2023-05-25 16:22:49 +02:00
|
|
|
// Don't barf if the model is not explicitly passed
|
|
|
|
$modelForForm = empty($data['model']) ?
|
|
|
|
h(\Cake\Utility\Inflector::singularize(\Cake\Utility\Inflector::classify($this->request->getParam('controller')))) :
|
|
|
|
h($data['model']);
|
2020-09-28 01:25:07 +02:00
|
|
|
$fieldTemplate = 'genericField';
|
2022-12-08 15:50:03 +01:00
|
|
|
if (!empty($fieldData['type'])) {
|
|
|
|
if (file_exists(ROOT . '/templates/element/genericElements/Form/Fields/' . $fieldData['type'] . 'Field.php')) {
|
|
|
|
$fieldTemplate = $fieldData['type'] . 'Field';
|
|
|
|
}
|
2020-09-28 01:25:07 +02:00
|
|
|
}
|
|
|
|
if (empty($fieldData['label'])) {
|
2021-11-03 11:47:10 +01:00
|
|
|
if (!isset($fieldData['label']) || $fieldData['label'] !== false) {
|
|
|
|
$fieldData['label'] = \Cake\Utility\Inflector::humanize($fieldData['field']);
|
|
|
|
}
|
2020-09-28 01:25:07 +02:00
|
|
|
}
|
2023-02-24 10:03:45 +01:00
|
|
|
$fieldDescription = $fieldData['tooltip'] ?? ($fieldDesc[$fieldData['field']] ?? false);
|
|
|
|
if (!empty($fieldDescription)) {
|
|
|
|
$fieldData['tooltip'] = $this->element(
|
2020-09-28 01:25:07 +02:00
|
|
|
'genericElements/Form/formInfo', array(
|
|
|
|
'field' => $fieldData,
|
2023-02-24 10:03:45 +01:00
|
|
|
'fieldDesc' => $fieldDescription,
|
2020-09-28 01:25:07 +02:00
|
|
|
'modelForForm' => $modelForForm
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$params = array();
|
|
|
|
if (!empty($fieldData['class'])) {
|
|
|
|
if (is_array($fieldData['class'])) {
|
|
|
|
$class = implode(' ', $fieldData['class']);
|
|
|
|
} else {
|
|
|
|
$class = $fieldData['class'];
|
|
|
|
}
|
|
|
|
$params['class'] = $class;
|
|
|
|
} else {
|
|
|
|
$params['class'] = '';
|
|
|
|
}
|
2021-12-08 11:08:40 +01:00
|
|
|
if (empty($fieldData['type']) || ($fieldData['type'] !== 'checkbox' && $fieldData['type'] !== 'radio')) {
|
2020-09-28 01:25:07 +02:00
|
|
|
$params['class'] .= ' form-control';
|
|
|
|
}
|
|
|
|
foreach ($fieldData as $k => $fd) {
|
|
|
|
if (!isset($simpleFieldWhitelist) || in_array($k, $simpleFieldWhitelist) || strpos($k, 'data-') === 0) {
|
|
|
|
$params[$k] = $fd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$temp = $this->element('genericElements/Form/Fields/' . $fieldTemplate, array(
|
|
|
|
'fieldData' => $fieldData,
|
|
|
|
'params' => $params
|
|
|
|
));
|
|
|
|
if (!empty($fieldData['hidden'])) {
|
|
|
|
$temp = '<span class="hidden">' . $temp . '</span>';
|
|
|
|
}
|
|
|
|
echo $temp;
|
|
|
|
} else {
|
|
|
|
echo $fieldData;
|
|
|
|
}
|