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 FieldRule records. |
11
|
|
|
*/ |
12
|
|
|
class FieldRule extends base\FieldRule implements Contract |
13
|
|
|
{ |
14
|
|
|
use ContractTrait { |
15
|
|
|
getLinks as getContractLinks; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @inheritdoc |
20
|
|
|
*/ |
21
|
|
|
protected $fieldClass = Field::class; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @inheritdoc |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
protected $propertyClass = FieldRuleProperty::class; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @inheritdoc |
31
|
|
|
*/ |
32
|
9 |
|
protected function slugBehaviorConfig(): array |
33
|
|
|
{ |
34
|
|
|
return [ |
35
|
9 |
|
'resourceName' => 'rule', |
36
|
9 |
|
'parentSlugRelation' => 'field', |
37
|
9 |
|
'checkAccess' => function ($params) { |
38
|
|
|
if ( |
39
|
8 |
|
isset($params['rule_id']) |
40
|
8 |
|
&& $params['rule_id'] != $this->id |
41
|
|
|
) { |
42
|
|
|
throw new NotFoundHttpException( |
43
|
|
|
'Field Rule doesnt contain the requested route.' |
44
|
|
|
); |
45
|
|
|
} |
46
|
9 |
|
} |
47
|
|
|
]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
*/ |
53
|
4 |
|
public function getLinks() |
54
|
|
|
{ |
55
|
4 |
|
$selfLink = $this->getSelfLink(); |
56
|
|
|
|
57
|
4 |
|
return array_merge($this->getContractLinks(), [ |
58
|
4 |
|
'properties' => $selfLink . '/property', |
59
|
|
|
'curies' => [ |
60
|
4 |
|
new Link([ |
61
|
4 |
|
'name' => 'embeddable', |
62
|
4 |
|
'href' => Url::to($selfLink, ['expand' => '{rel}']), |
|
|
|
|
63
|
4 |
|
'title' => 'Embeddable and not Nestable related resources.', |
64
|
|
|
]), |
65
|
4 |
|
new Link([ |
66
|
4 |
|
'name' => 'nestable', |
67
|
4 |
|
'href' => Url::to($selfLink, ['expand' => '{rel}']), |
68
|
4 |
|
'title' => 'Embeddable and Nestable related resources.', |
69
|
|
|
]), |
70
|
|
|
], |
71
|
4 |
|
'embeddable:properties' => 'properties', |
72
|
4 |
|
'nestable:field' => 'field', |
73
|
|
|
]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
*/ |
79
|
4 |
|
public function extraFields() |
80
|
|
|
{ |
81
|
4 |
|
return ['field', 'properties']; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|