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
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* ROA contract handling Section records. |
13
|
|
|
*/ |
14
|
|
|
class Section extends base\Section implements Contract |
15
|
|
|
{ |
16
|
|
|
use ContractTrait { |
17
|
|
|
getLinks as getContractLinks; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @inheritdoc |
22
|
|
|
*/ |
23
|
|
|
protected $formClass = Form::class; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @inheritdoc |
27
|
|
|
*/ |
28
|
|
|
protected $sectionFieldClass = SectionField::class; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @inheritdoc |
32
|
|
|
*/ |
33
|
|
|
protected $fieldClass = Field::class; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritdoc |
37
|
|
|
*/ |
38
|
4 |
|
public function getLinks() |
39
|
|
|
{ |
40
|
4 |
|
$selfLink = $this->getSelfLink(); |
41
|
|
|
|
42
|
4 |
|
return array_merge($this->getContractLinks(), [ |
43
|
4 |
|
'fields' => $selfLink . '/field', |
44
|
|
|
'curies' => [ |
45
|
4 |
|
new Link([ |
46
|
4 |
|
'name' => 'embeddable', |
47
|
4 |
|
'href' => Url::to($selfLink, ['expand' => '{rel}']), |
|
|
|
|
48
|
4 |
|
'title' => 'Embeddable and not Nestable related resources.', |
49
|
|
|
]), |
50
|
4 |
|
new Link([ |
51
|
4 |
|
'name' => 'nestable', |
52
|
4 |
|
'href' => Url::to($selfLink, ['expand' => '{rel}']), |
53
|
4 |
|
'title' => 'Embeddable and Nestable related resources.', |
54
|
|
|
]), |
55
|
|
|
], |
56
|
4 |
|
'embeddable:fields' => 'fields', |
57
|
4 |
|
'nestable:form' => 'form', |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @inheritdoc |
63
|
|
|
*/ |
64
|
15 |
|
protected function slugBehaviorConfig(): array |
65
|
|
|
{ |
66
|
|
|
return [ |
67
|
15 |
|
'resourceName' => 'section', |
68
|
|
|
'parentSlugRelation' => 'form', |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritdoc |
74
|
|
|
*/ |
75
|
4 |
|
public function extraFields() |
76
|
|
|
{ |
77
|
4 |
|
return ['form', 'fields', 'sectionFields']; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|