/
VocabulariesTable.php
65 lines (56 loc) · 1.74 KB
/
VocabulariesTable.php
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
<?php
declare(strict_types=1);
namespace Croogo\Taxonomy\Model\Table;
use Cake\ORM\RulesChecker;
use Cake\Validation\Validator;
use Croogo\Core\Model\Table\CroogoTable;
/**
* @property TaxonomiesTable Taxonomies
*/
class VocabulariesTable extends CroogoTable
{
public function initialize(array $config): void
{
$this->addBehavior('ADmad/Sequence.Sequence', [
'sequenceField' => 'weight',
]);
$this->addBehavior('Timestamp');
$this->addBehavior('Search.Search');
$this->addBehavior('Croogo/Core.Sluggable', [
'slugField' => 'alias',
]);
$this->addBehavior('Croogo/Core.Trackable');
$this->addBehavior('Croogo/Core.Cached', [
'groups' => ['taxonomy']
]);
$this->belongsToMany('Croogo/Taxonomy.Types', [
'through' => 'Croogo/Taxonomy.TypesVocabularies',
]);
$this->hasMany('Croogo/Taxonomy.Taxonomies', [
'dependent' => true,
]);
}
/**
* @param \Cake\Validation\Validator $validator
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->notBlank('title', __d('croogo', 'The title cannot be empty'))
->notBlank('alias', __d('croogo', 'The alias cannot be empty'));
return parent::validationDefault($validator);
}
/**
* @param \Cake\ORM\RulesChecker $rules
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(
['alias'],
__d('croogo', 'That alias is already taken')
));
return parent::buildRules($rules);
}
}