1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
<?php
namespace BEdita\Core\Model\Validation;
use Cake\ORM\TableRegistry;
use Cake\Validation\Validator;
class ObjectTypesValidator extends Validator
{
public function __construct()
{
parent::__construct();
$this->setProvider('table', TableRegistry::getTableLocator()->get('ObjectTypes'));
$this->setProvider('bedita', Validation::class);
$this
->integer('id')
->allowEmptyString('id', null, 'create');
$this
->requirePresence('name', 'create')
->notEmptyString('name')
->regex('name', '/^([a-zA-Z]+)/')
->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table'])
->add('name', 'notReserved', ['rule' => 'notReserved', 'provider' => 'bedita']);
$this
->requirePresence('singular', 'create')
->notEmptyString('singular')
->regex('singular', '/^([a-zA-Z]+)/')
->add('singular', 'notSameAs', [
'rule' => function ($value, $context) {
if (empty($context['data']['name'])) {
return true;
}
return $context['data']['name'] !== $value;
},
'message' => __d('bedita', 'Name and singular fields must be different'),
])
->add('singular', 'unique', ['rule' => 'validateUnique', 'provider' => 'table'])
->add('singular', 'notReserved', ['rule' => 'notReserved', 'provider' => 'bedita']);
$this
->allowEmptyString('description');
$this
->allowEmptyString('associations');
$this
->allowEmptyString('hidden');
return $this;
}
}