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