|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Website\Form\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Constant\Html5; |
|
8
|
|
|
use AbterPhp\Framework\Form\Container\FormGroup; |
|
9
|
|
|
use AbterPhp\Framework\Form\Container\Hideable; |
|
10
|
|
|
use AbterPhp\Framework\Form\Element\Input; |
|
11
|
|
|
use AbterPhp\Framework\Form\Element\Textarea; |
|
12
|
|
|
use AbterPhp\Framework\Form\Factory\Base; |
|
13
|
|
|
use AbterPhp\Framework\Form\Factory\IFormFactory; |
|
14
|
|
|
use AbterPhp\Framework\Form\IForm; |
|
15
|
|
|
use AbterPhp\Framework\Form\Label\Label; |
|
16
|
|
|
use AbterPhp\Framework\I18n\ITranslator; |
|
17
|
|
|
use AbterPhp\Website\Domain\Entities\PageCategory as Entity; |
|
18
|
|
|
use Opulence\Orm\IEntity; |
|
19
|
|
|
use Opulence\Sessions\ISession; |
|
20
|
|
|
|
|
21
|
|
|
class PageCategory extends Base |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* PageLayout constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param ISession $session |
|
27
|
|
|
* @param ITranslator $translator |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(ISession $session, ITranslator $translator) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct($session, $translator); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param string $action |
|
36
|
|
|
* @param string $method |
|
37
|
|
|
* @param string $showUrl |
|
38
|
|
|
* @param IEntity|null $entity |
|
39
|
|
|
* |
|
40
|
|
|
* @return IForm |
|
41
|
|
|
*/ |
|
42
|
|
|
public function create(string $action, string $method, string $showUrl, ?IEntity $entity = null): IForm |
|
43
|
|
|
{ |
|
44
|
|
|
if (!($entity instanceof Entity)) { |
|
45
|
|
|
throw new \InvalidArgumentException(IFormFactory::ERR_MSG_ENTITY_MISSING); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$this->createForm($action, $method) |
|
49
|
|
|
->addDefaultElements() |
|
50
|
|
|
->addIdentifier($entity) |
|
51
|
|
|
->addName($entity) |
|
52
|
|
|
->addDefaultButtons($showUrl); |
|
53
|
|
|
|
|
54
|
|
|
$form = $this->form; |
|
55
|
|
|
|
|
56
|
|
|
$this->form = null; |
|
57
|
|
|
|
|
58
|
|
|
return $form; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param Entity $entity |
|
63
|
|
|
* |
|
64
|
|
|
* @return $this |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function addIdentifier(Entity $entity): PageCategory |
|
67
|
|
|
{ |
|
68
|
|
|
$input = new Input('identifier', 'identifier', $entity->getIdentifier()); |
|
69
|
|
|
$label = new Label('identifier', 'website:pageCategoryIdentifier'); |
|
70
|
|
|
|
|
71
|
|
|
$this->form[] = new FormGroup($input, $label, null); |
|
72
|
|
|
|
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param Entity $entity |
|
78
|
|
|
* |
|
79
|
|
|
* @return $this |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function addName(Entity $entity): PageCategory |
|
82
|
|
|
{ |
|
83
|
|
|
$input = new Input('name', 'name', $entity->getIdentifier()); |
|
84
|
|
|
$label = new Label('name', 'website:pageCategoryName'); |
|
85
|
|
|
|
|
86
|
|
|
$this->form[] = new FormGroup($input, $label); |
|
87
|
|
|
|
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|