|
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 Form records. |
|
11
|
|
|
*/ |
|
12
|
|
|
class Form extends base\Form implements Contract |
|
13
|
|
|
{ |
|
14
|
|
|
use ContractTrait { |
|
15
|
|
|
getLinks as getContractLinks; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @inheritdoc |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $sectionClass = Section::class; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @inheritdoc |
|
25
|
|
|
*/ |
|
26
|
5 |
|
public function getLinks() |
|
27
|
|
|
{ |
|
28
|
5 |
|
$selfLink = $this->getSelfLink(); |
|
29
|
|
|
|
|
30
|
5 |
|
return array_merge($this->getContractLinks(), [ |
|
31
|
5 |
|
'sections' => $selfLink . '/section', |
|
32
|
|
|
'curies' => [ |
|
33
|
5 |
|
new Link([ |
|
34
|
5 |
|
'name' => 'embeddable', |
|
35
|
5 |
|
'href' => Url::to($selfLink, ['expand' => '{rel}']), |
|
|
|
|
|
|
36
|
5 |
|
'title' => 'Embeddable and not Nestable related resources.', |
|
37
|
|
|
]), |
|
38
|
|
|
], |
|
39
|
5 |
|
'embeddable:sections' => 'sections', |
|
40
|
|
|
]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @inheritdoc |
|
45
|
|
|
*/ |
|
46
|
26 |
|
protected function slugBehaviorConfig(): array |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
26 |
|
'resourceName' => 'form', |
|
50
|
26 |
|
'checkAccess' => function ($params) { |
|
51
|
|
|
if ( |
|
52
|
24 |
|
isset($params['form_id']) |
|
53
|
24 |
|
&& $params['form_id'] != $this->id |
|
54
|
|
|
) { |
|
55
|
5 |
|
throw new NotFoundHttpException( |
|
56
|
5 |
|
'Field doesnt contain the requested route.' |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
26 |
|
}, |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @inheritdoc |
|
65
|
|
|
*/ |
|
66
|
5 |
|
public function extraFields() |
|
67
|
|
|
{ |
|
68
|
5 |
|
return ['sections']; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|