2021-12-01 11:01:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Model\Entity;
|
|
|
|
|
|
|
|
use App\Model\Entity\AppModel;
|
|
|
|
use Cake\ORM\Entity;
|
|
|
|
|
|
|
|
class MetaTemplateField extends AppModel
|
|
|
|
{
|
2022-11-15 14:54:44 +01:00
|
|
|
protected $_virtual = ['index_type', 'form_type', 'form_options', ];
|
|
|
|
|
|
|
|
protected function _getIndexType()
|
|
|
|
{
|
|
|
|
$indexType = 'text';
|
|
|
|
if ($this->type === 'boolean') {
|
|
|
|
$indexType = 'boolean';
|
|
|
|
} else if ($this->type === 'date') {
|
|
|
|
$indexType = 'datetime';
|
|
|
|
} else if ($this->type === 'ipv4' || $this->type === 'ipv6') {
|
|
|
|
$indexType = 'text';
|
|
|
|
}
|
|
|
|
return $indexType;
|
|
|
|
}
|
2022-11-14 09:04:35 +01:00
|
|
|
|
|
|
|
protected function _getFormType()
|
|
|
|
{
|
|
|
|
$formType = 'text';
|
|
|
|
if (!empty($this->sane_default) || !empty($this->values_list)) {
|
|
|
|
$formType = 'dropdown';
|
2022-11-14 15:45:28 +01:00
|
|
|
} else if ($this->type === 'boolean') {
|
|
|
|
$formType = 'checkbox';
|
2022-11-14 09:04:35 +01:00
|
|
|
}
|
|
|
|
return $formType;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function _getFormOptions()
|
|
|
|
{
|
|
|
|
$formOptions = [];
|
|
|
|
if ($this->formType === 'dropdown') {
|
|
|
|
$selectOptions = !empty($this->sane_default) ? $this->sane_default : $this->values_list;
|
|
|
|
$selectOptions = array_combine($selectOptions, $selectOptions);
|
|
|
|
if (!empty($this->sane_default)) {
|
|
|
|
$selectOptions[] = ['value' => '_custom', 'text' => __('-- custom value --'), 'class' => 'custom-value'];
|
|
|
|
}
|
|
|
|
$selectOptions[''] = __('-- no value --');
|
|
|
|
$formOptions['options'] = $selectOptions;
|
|
|
|
}
|
|
|
|
return $formOptions;
|
|
|
|
}
|
2021-12-01 11:01:31 +01:00
|
|
|
|
|
|
|
}
|