Passed
Push — master ( 8f0f73...d2306b )
by Peter
02:30
created

Advanced::addWithBody()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 17
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Form\Factory\ContentList;
6
7
use AbterPhp\Framework\Constant\Html5;
8
use AbterPhp\Framework\Form\Container\CheckboxGroup;
9
use AbterPhp\Framework\Form\Container\FormGroup;
10
use AbterPhp\Framework\Form\Element\Input;
11
use AbterPhp\Framework\Form\Extra\Help;
12
use AbterPhp\Framework\Form\Label\Label;
13
use AbterPhp\Framework\Html\INode;
14
use AbterPhp\Framework\I18n\ITranslator;
15
use AbterPhp\Website\Domain\Entities\ContentList as Entity;
16
17
class Advanced
18
{
19
    /** @var ITranslator */
20
    protected $translator;
21
22
    /** @var array */
23
    protected $hiddenAttribs = [Html5::ATTR_TYPE => Input::TYPE_HIDDEN];
24
25
    /**
26
     * Hideable constructor.
27
     *
28
     * @param ITranslator $translator
29
     */
30
    public function __construct(ITranslator $translator)
31
    {
32
        $this->translator = $translator;
33
    }
34
35
    /**
36
     * @param Entity $entity
37
     *
38
     * @return INode[]
39
     */
40
    public function create(Entity $entity): array
41
    {
42
        $components = [];
43
44
        $components[] = $this->addClasses($entity);
45
        $components[] = $this->addProtected($entity);
46
        $components[] = $this->addWithLinks($entity);
47
        $components[] = $this->addWithImage($entity);
48
        $components[] = $this->addWithBody($entity);
49
        $components[] = $this->addWithHtml($entity);
50
51
        return $components;
52
    }
53
54
    /**
55
     * @param Entity $entity
56
     *
57
     * @return INode
58
     */
59
    protected function addClasses(Entity $entity): INode
60
    {
61
        $input = new Input('classes', 'classes', $entity->getClasses());
62
        $label = new Label('classes', 'website:contentListClasses');
63
        $help  = new Help('website:contentListClassesHelp');
64
65
        return new FormGroup($input, $label, $help);
66
    }
67
68
    /**
69
     * @param Entity $entity
70
     *
71
     * @return INode
72
     */
73
    protected function addProtected(Entity $entity): INode
74
    {
75
        $attributes = [Html5::ATTR_TYPE => Input::TYPE_CHECKBOX];
76
        if ($entity->isProtected()) {
77
            $attributes[Html5::ATTR_CHECKED] = null;
78
        }
79
        $input = new Input(
80
            'protected',
81
            'protected',
82
            '1',
83
            [],
84
            $attributes
85
        );
86
        $label = new Label('protected', 'website:contentListProtected');
87
        $help  = new Help('website:contentListProtectedHelp');
88
89
        return new CheckboxGroup($input, $label, $help, [], [Html5::ATTR_ID => 'protected-container']);
90
    }
91
92
    /**
93
     * @param Entity $entity
94
     *
95
     * @return INode
96
     */
97
    protected function addWithImage(Entity $entity): INode
98
    {
99
        $attributes = [Html5::ATTR_TYPE => Input::TYPE_CHECKBOX];
100
        if ($entity->isWithImage()) {
101
            $attributes[Html5::ATTR_CHECKED] = null;
102
        }
103
        $input = new Input(
104
            'with_image',
105
            'with_image',
106
            '1',
107
            [],
108
            $attributes
109
        );
110
        $label = new Label('with_image', 'website:contentListWithImage');
111
        $help  = new Help('website:contentListWithImageHelp');
112
113
        return new CheckboxGroup($input, $label, $help, [], [Html5::ATTR_ID => 'withImage-container']);
114
    }
115
116
    /**
117
     * @param Entity $entity
118
     *
119
     * @return INode
120
     */
121
    protected function addWithLinks(Entity $entity): INode
122
    {
123
        $attributes = [Html5::ATTR_TYPE => Input::TYPE_CHECKBOX];
124
        if ($entity->isWithLinks()) {
125
            $attributes[Html5::ATTR_CHECKED] = null;
126
        }
127
        $input = new Input(
128
            'with_links',
129
            'with_links',
130
            '1',
131
            [],
132
            $attributes
133
        );
134
        $label = new Label('with_links', 'website:contentListWithLinks');
135
        $help  = new Help('website:contentListWithLinksHelp');
136
137
        return new CheckboxGroup($input, $label, $help, [], [Html5::ATTR_ID => 'withLinks-container']);
138
    }
139
140
    /**
141
     * @param Entity $entity
142
     *
143
     * @return INode
144
     */
145
    protected function addWithBody(Entity $entity): INode
146
    {
147
        $attributes = [Html5::ATTR_TYPE => Input::TYPE_CHECKBOX];
148
        if ($entity->isWithBody()) {
149
            $attributes[Html5::ATTR_CHECKED] = null;
150
        }
151
        $input = new Input(
152
            'with_body',
153
            'with_body',
154
            '1',
155
            [],
156
            $attributes
157
        );
158
        $label = new Label('with_body', 'website:contentListWithBody');
159
        $help  = new Help('website:contentListWithBodyHelp');
160
161
        return new CheckboxGroup($input, $label, $help, [], [Html5::ATTR_ID => 'withBody-container']);
162
    }
163
164
    /**
165
     * @param Entity $entity
166
     *
167
     * @return INode
168
     */
169
    protected function addWithHtml(Entity $entity): INode
170
    {
171
        $attributes = [Html5::ATTR_TYPE => Input::TYPE_CHECKBOX];
172
        if ($entity->isWithHtml()) {
173
            $attributes[Html5::ATTR_CHECKED] = null;
174
        }
175
        $input = new Input(
176
            'with_html',
177
            'with_html',
178
            '1',
179
            [],
180
            $attributes
181
        );
182
        $label = new Label('with_html', 'website:contentListWithHtml');
183
        $help  = new Help('website:contentListWithHtmlHelp');
184
185
        return new CheckboxGroup($input, $label, $help, [], [Html5::ATTR_ID => 'withHtml-container']);
186
    }
187
}
188