Passed
Pull Request — master (#1)
by Peter
03:15
created

ContentList   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createEntity() 0 3 1
A addCustomAssets() 0 17 2
A __construct() 0 24 1
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\Domain\Entities\IStringerEntity;
10
use AbterPhp\Framework\I18n\ITranslator;
11
use AbterPhp\Framework\Session\FlashService;
12
use AbterPhp\Website\Domain\Entities\ContentList as Entity;
13
use AbterPhp\Website\Form\Factory\ContentList as FormFactory;
14
use AbterPhp\Website\Orm\ContentListRepo as Repo;
15
use Opulence\Events\Dispatchers\IEventDispatcher;
16
use Opulence\Routing\Urls\UrlGenerator;
17
use Opulence\Sessions\ISession;
18
use Psr\Log\LoggerInterface;
19
20
class ContentList extends FormAbstract
21
{
22
    const ENTITY_SINGULAR = 'contentList';
23
    const ENTITY_PLURAL   = 'contentLists';
24
25
    const ENTITY_TITLE_SINGULAR = 'website:contentList';
26
    const ENTITY_TITLE_PLURAL   = 'website:contentLists';
27
28
    /** @var AssetManager */
29
    protected $assetManager;
30
31
    /** @var string */
32
    protected $resource = 'lists';
33
34
    /**
35
     * Block constructor.
36
     *
37
     * @param FlashService     $flashService
38
     * @param ITranslator      $translator
39
     * @param UrlGenerator     $urlGenerator
40
     * @param LoggerInterface  $logger
41
     * @param Repo             $repo
42
     * @param ISession         $session
43
     * @param IEventDispatcher $eventDispatcher
44
     * @param FormFactory      $formFactory
45
     * @param AssetManager     $assetManager
46
     */
47
    public function __construct(
48
        FlashService $flashService,
49
        ITranslator $translator,
50
        UrlGenerator $urlGenerator,
51
        LoggerInterface $logger,
52
        Repo $repo,
53
        ISession $session,
54
        IEventDispatcher $eventDispatcher,
55
        FormFactory $formFactory,
56
        AssetManager $assetManager
57
    ) {
58
        parent::__construct(
59
            $flashService,
60
            $translator,
61
            $urlGenerator,
62
            $logger,
63
            $repo,
64
            $session,
65
            $formFactory,
66
            $eventDispatcher
67
        );
68
69
        $this->formFactory  = $formFactory;
70
        $this->assetManager = $assetManager;
71
    }
72
73
    /**
74
     * @param string $entityId
75
     *
76
     * @return Entity
77
     */
78
    protected function createEntity(string $entityId): IStringerEntity
79
    {
80
        return new Entity($entityId, '', '', '', false, false, false, false);
81
    }
82
83
    /**
84
     * @param IStringerEntity|null $entity
85
     *
86
     * @throws \League\Flysystem\FileNotFoundException
87
     */
88
    protected function addCustomAssets(?IStringerEntity $entity = null)
89
    {
90
        parent::addCustomAssets($entity);
91
92
        if (!($entity instanceof Entity)) {
93
            return;
94
        }
95
96
        $styles = $this->getResourceName(static::RESOURCE_DEFAULT);
97
        $this->assetManager->addCss($styles, '/admin-assets/vendor/trumbowyg/ui/trumbowyg.css');
98
        $this->assetManager->addCss($styles, '/admin-assets/css/list.css');
99
100
        $footer = $this->getResourceName(static::RESOURCE_FOOTER);
101
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/trumbowyg.js');
102
        $this->assetManager->addJs($footer, '/admin-assets/vendor/trumbowyg/langs/hu.js');
103
        $this->assetManager->addJs($footer, '/admin-assets/js/editor.js');
104
        $this->assetManager->addJs($footer, '/admin-assets/js/list.js');
105
    }
106
}
107