Passed
Push — master ( f6fb5e...281f71 )
by Peter
02:15
created

Assets::addClasses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Form\Factory\PageLayout;
6
7
use AbterPhp\Framework\Form\Container\FormGroup;
8
use AbterPhp\Framework\Form\Element\Textarea;
9
use AbterPhp\Framework\Form\Extra\Help;
10
use AbterPhp\Framework\Form\Label\Label;
11
use AbterPhp\Framework\Html\INode;
12
use AbterPhp\Website\Domain\Entities\PageLayout as Entity;
13
14
class Assets
15
{
16
    /**
17
     * @return INode[]
18
     */
19
    public function create(Entity $entity): array
20
    {
21
        $components = [];
22
23
        $components[] = $this->addClasses($entity);
24
        $components[] = $this->addHeader($entity);
25
        $components[] = $this->addFooter($entity);
26
        $components[] = $this->addCssFiles($entity);
27
        $components[] = $this->addJsFiles($entity);
28
29
        return $components;
30
    }
31
32
    /**
33
     * @param Entity $entity
34
     *
35
     * @return INode
36
     */
37
    protected function addClasses(Entity $entity): INode
38
    {
39
        $input = new Textarea('classes', 'classes', $entity->getClasses());
40
        $label = new Label('classes', 'website:pageClasses');
41
        $help  = new Help('website:pageClassesHelp');
42
43
        return new FormGroup($input, $label, $help);
44
    }
45
46
    /**
47
     * @param Entity $entity
48
     *
49
     * @return INode
50
     */
51
    protected function addHeader(Entity $entity): INode
52
    {
53
        $header = $entity->getAssets() ? $entity->getAssets()->getHeader() : '';
54
55
        $input = new Textarea('header', 'header', $header);
56
        $label = new Label('header', 'website:pageLayoutHeader');
57
        $help  = new Help('website:pageLayoutHeaderHelp');
58
59
        return new FormGroup($input, $label, $help);
60
    }
61
62
    /**
63
     * @param Entity $entity
64
     *
65
     * @return INode
66
     */
67
    protected function addFooter(Entity $entity): INode
68
    {
69
        $footer = $entity->getAssets() ? $entity->getAssets()->getFooter() : '';
70
71
        $input = new Textarea('footer', 'footer', $footer);
72
        $label = new Label('footer', 'website:pageLayoutFooter');
73
        $help  = new Help('website:pageLayoutHeaderHelp');
74
75
        return new FormGroup($input, $label, $help);
76
    }
77
78
    /**
79
     * @param Entity $entity
80
     *
81
     * @return INode
82
     */
83
    protected function addCssFiles(Entity $entity): INode
84
    {
85
        $cssFiles = $entity->getAssets() ? $entity->getAssets()->getCssFiles() : [];
86
87
        $input = new Textarea('css-files', 'css-files', implode("\r\n", $cssFiles));
88
        $label = new Label('css-files', 'website:pageLayoutCssFiles');
89
        $help  = new Help('website:pageLayoutCssFilesHelp');
90
91
        return new FormGroup($input, $label, $help);
92
    }
93
94
    /**
95
     * @param Entity $entity
96
     *
97
     * @return INode
98
     */
99
    protected function addJsFiles(Entity $entity): INode
100
    {
101
        $jsFiles = $entity->getAssets() ? $entity->getAssets()->getJsFiles() : [];
102
103
        $input = new Textarea('js-files', 'js-files', implode("\r\n", $jsFiles));
104
        $label = new Label('js-files', 'website:pageLayoutJsFiles');
105
        $help  = new Help('website:pageLayoutJsFilesHelp');
106
107
        return new FormGroup($input, $label, $help);
108
    }
109
}
110