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