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