|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace roaresearch\yii2\formgenerator\roa\models; |
|
4
|
|
|
|
|
5
|
|
|
use roaresearch\yii2\formgenerator\models as base; |
|
6
|
|
|
use roaresearch\yii2\roa\hal\{Contract, ContractTrait}; |
|
7
|
|
|
use yii\{helpers\Url, web\Link, web\NotFoundHttpException}; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* ROA contract handling Field records. |
|
11
|
|
|
*/ |
|
12
|
|
|
class Field extends base\Field implements Contract |
|
13
|
|
|
{ |
|
14
|
|
|
use ContractTrait { |
|
15
|
|
|
getLinks as getContractLinks; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @inheritdoc |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $dataTypeClass = DataType::class; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @inheritdoc |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $ruleClass = FieldRule::class; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @inheritdoc |
|
30
|
|
|
*/ |
|
31
|
23 |
|
protected function slugBehaviorConfig(): array |
|
32
|
|
|
{ |
|
33
|
|
|
return [ |
|
34
|
23 |
|
'resourceName' => 'field', |
|
35
|
23 |
|
'checkAccess' => function ($params) { |
|
36
|
|
|
if ( |
|
37
|
12 |
|
isset($params['field_id']) |
|
38
|
12 |
|
&& $params['field_id'] != $this->id |
|
39
|
|
|
) { |
|
40
|
1 |
|
throw new NotFoundHttpException( |
|
41
|
1 |
|
'Field doesnt contain the requested route.' |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
23 |
|
}, |
|
45
|
|
|
]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @inheritdoc |
|
50
|
|
|
*/ |
|
51
|
5 |
|
public function getLinks() |
|
52
|
|
|
{ |
|
53
|
5 |
|
$selfLink = $this->getSelfLink(); |
|
54
|
|
|
|
|
55
|
5 |
|
return array_merge($this->getContractLinks(), [ |
|
56
|
5 |
|
'rules' => $selfLink . '/rule', |
|
57
|
|
|
'curies' => [ |
|
58
|
5 |
|
new Link([ |
|
59
|
5 |
|
'name' => 'embeddable', |
|
60
|
5 |
|
'href' => Url::to($selfLink, ['expand' => '{rel}']), |
|
|
|
|
|
|
61
|
5 |
|
'title' => 'Embeddable and not Nestable related resources.', |
|
62
|
|
|
]), |
|
63
|
5 |
|
new Link([ |
|
64
|
5 |
|
'name' => 'nestable', |
|
65
|
5 |
|
'href' => Url::to($selfLink, ['expand' => '{rel}']), |
|
66
|
5 |
|
'title' => 'Embeddable and Nestable related resources.', |
|
67
|
|
|
]), |
|
68
|
|
|
], |
|
69
|
5 |
|
'embeddable:rules' => 'rules', |
|
70
|
5 |
|
'nestable:dataType' => 'dataType', |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @inheritdoc |
|
76
|
|
|
*/ |
|
77
|
5 |
|
public function extraFields() |
|
78
|
|
|
{ |
|
79
|
5 |
|
return ['dataType', 'rules']; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|