ContentList   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 58
c 1
b 0
f 0
dl 0
loc 131
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createEntity() 0 3 1
A __construct() 0 26 1
A addCustomAssets() 0 55 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Http\Controllers\Admin\Form;
6
7
use AbterPhp\Admin\Http\Controllers\Admin\FormAbstract;
8
use AbterPhp\Framework\Assets\AssetManager;
9
use AbterPhp\Framework\Config\EnvReader;
10
use AbterPhp\Framework\Constant\Session;
11
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
12
use AbterPhp\Framework\I18n\ITranslator;
13
use AbterPhp\Framework\Session\FlashService;
14
use AbterPhp\Website\Domain\Entities\ContentList as Entity;
15
use AbterPhp\Website\Form\Factory\ContentList as FormFactory;
16
use AbterPhp\Website\Orm\ContentListRepo as Repo;
17
use League\Flysystem\FilesystemException;
18
use Opulence\Events\Dispatchers\IEventDispatcher;
19
use Opulence\Routing\Urls\UrlGenerator;
20
use Opulence\Sessions\ISession;
21
use Psr\Log\LoggerInterface;
22
23
/**
24
 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
25
 */
26
class ContentList extends FormAbstract
27
{
28
    const ENTITY_SINGULAR = 'contentList';
29
    const ENTITY_PLURAL   = 'contentLists';
30
31
    const ENTITY_TITLE_SINGULAR = 'website:contentList';
32
    const ENTITY_TITLE_PLURAL   = 'website:contentLists';
33
34
    const ROUTING_PATH = 'lists';
35
36
    /** @var AssetManager */
37
    protected $assetManager;
38
39
    /** @var EnvReader */
40
    protected $envReader;
41
42
    /** @var string */
43
    protected $resource = 'lists';
44
45
    /**
46
     * Block constructor.
47
     *
48
     * @param FlashService     $flashService
49
     * @param LoggerInterface  $logger
50
     * @param ITranslator      $translator
51
     * @param UrlGenerator     $urlGenerator
52
     * @param Repo             $repo
53
     * @param ISession         $session
54
     * @param IEventDispatcher $eventDispatcher
55
     * @param FormFactory      $formFactory
56
     * @param AssetManager     $assetManager
57
     * @param EnvReader        $envReader
58
     */
59
    public function __construct(
60
        FlashService $flashService,
61
        LoggerInterface $logger,
62
        ITranslator $translator,
63
        UrlGenerator $urlGenerator,
64
        Repo $repo,
65
        ISession $session,
66
        IEventDispatcher $eventDispatcher,
67
        FormFactory $formFactory,
68
        AssetManager $assetManager,
69
        EnvReader $envReader
70
    ) {
71
        parent::__construct(
72
            $flashService,
73
            $logger,
74
            $translator,
75
            $urlGenerator,
76
            $repo,
77
            $session,
78
            $formFactory,
79
            $eventDispatcher
80
        );
81
82
        $this->formFactory  = $formFactory;
83
        $this->assetManager = $assetManager;
84
        $this->envReader    = $envReader;
85
    }
86
87
    /**
88
     * @param string $entityId
89
     *
90
     * @return Entity
91
     */
92
    protected function createEntity(string $entityId): IStringerEntity
93
    {
94
        return new Entity($entityId, '', '', '', false, false, false, false, false, false);
95
    }
96
97
    /**
98
     * @param IStringerEntity|null $entity
99
     *
100
     * @throws FilesystemException
101
     */
102
    protected function addCustomAssets(?IStringerEntity $entity = null)
103
    {
104
        parent::addCustomAssets($entity);
105
106
        if (!($entity instanceof Entity)) {
107
            return;
108
        }
109
110
        $styles = $this->getResourceName(static::RESOURCE_DEFAULT);
111
        $footer = $this->getResourceName(static::RESOURCE_FOOTER);
112
113
        // Feature is disabled in favor of the base64 plugin
114
        //$editorFileUploadPath = Routes::getApiBasePath() . '/editor-file-upload';
115
        //$this->assetManager->addJsVar('clientId', $this->envReader->get(AdminEnv::EDITOR_CLIENT_ID));
116
        //$this->assetManager->addJsVar('editorFileUploadPath', $this->envReader->get(AdminEnv::EDITOR_CLIENT_ID));
117
118
        $editorLang = $this->session->get(Session::LANGUAGE_IDENTIFIER);
119
        $this->assetManager->addJsVar($footer, 'editorLang', $editorLang);
120
121
        $this->assetManager->addCss($styles, '/admin-assets/vendor/trumbowyg/ui/trumbowyg.css');
122
        $this->assetManager->addCss($styles, '/admin-assets/vendor/trumbowyg/plugins/table/ui/trumbowyg.table.css');
123
        $this->assetManager->addCss(
124
            $styles,
125
            '/admin-assets/vendor/trumbowyg/plugins/specialchars/ui/trumbowyg.specialchars.css'
126
        );
127
        $this->assetManager->addCss($styles, '/admin-assets/css/trumbowyg.css');
128
        $this->assetManager->addCss($styles, '/admin-assets/css/list.css');
129
130
        $this->assetManager->addJs($footer, '/admin-assets/vendor/jquery/jquery-resizable.js');
131
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/trumbowyg.js');
132
        $this->assetManager->addJs($footer, "/admin-assets/vendor/trumbowyg/langs/${editorLang}.js");
133
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/plugins/base64/trumbowyg.base64.js');
134
        $this->assetManager->addJs(
135
            $footer,
136
            '/admin-assets/vendor/trumbowyg/plugins/cleanpaste/trumbowyg.cleanpaste.js'
137
        );
138
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/plugins/history/trumbowyg.history.js');
139
        $this->assetManager->addJs(
140
            $footer,
141
            '/admin-assets/vendor/trumbowyg/plugins/preformatted/trumbowyg.preformatted.js'
142
        );
143
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/plugins/resizimg/trumbowyg.resizimg.js');
144
        $this->assetManager->addJs(
145
            $footer,
146
            '/admin-assets/vendor/trumbowyg/plugins/specialchars/trumbowyg.specialchars.js'
147
        );
148
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/plugins/table/trumbowyg.table.js');
149
        // Feature is disabled in favor of the base64 plugin
150
        //$this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/plugins/upload/trumbowyg.upload.js');
151
        $this->assetManager->addJs($footer, '/admin-assets/js/editor.js');
152
        $this->assetManager->addJs($footer, '/admin-assets/js/list.js');
153
        $this->assetManager->addJs($footer, '/admin-assets/js/hideable-container.js');
154
        $this->assetManager->addJs($footer, '/admin-assets/js/semi-auto.js');
155
        $this->assetManager->addJs($footer, '/admin-assets/js/required.js');
156
        $this->assetManager->addJs($footer, '/admin-assets/js/validation.js');
157
    }
158
}
159