Passed
Push — master ( ccabb0...25c117 )
by Peter
02:15
created

FileCategory::addCustomAssets()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Files\Http\Controllers\Admin\Form;
6
7
use AbterPhp\Admin\Http\Controllers\Admin\FormAbstract;
8
use AbterPhp\Framework\Assets\AssetManager;
9
use AbterPhp\Files\Domain\Entities\FileCategory as Entity;
10
use AbterPhp\Files\Form\Factory\FileCategory as FormFactory;
11
use AbterPhp\Files\Orm\FileCategoryRepo as Repo;
12
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
13
use AbterPhp\Framework\I18n\ITranslator;
14
use AbterPhp\Framework\Session\FlashService;
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 FileCategory extends FormAbstract
21
{
22
    const ENTITY_PLURAL   = 'fileCategories';
23
    const ENTITY_SINGULAR = 'fileCategory';
24
25
    const ENTITY_TITLE_SINGULAR = 'files:fileCategory';
26
    const ENTITY_TITLE_PLURAL   = 'files:fileCategories';
27
28
    const ROUTING_PATH = 'file-categories';
29
30
    /** @var AssetManager */
31
    protected $assetManager;
32
33
    /** @var string */
34
    protected $resource = 'file_categories';
35
36
    /**
37
     * FileCategory constructor.
38
     *
39
     * @param FlashService     $flashService
40
     * @param ITranslator      $translator
41
     * @param UrlGenerator     $urlGenerator
42
     * @param LoggerInterface  $logger
43
     * @param Repo             $repo
44
     * @param ISession         $session
45
     * @param FormFactory      $formFactory
46
     * @param IEventDispatcher $eventDispatcher
47
     * @param AssetManager     $assetManager
48
     */
49
    public function __construct(
50
        FlashService $flashService,
51
        ITranslator $translator,
52
        UrlGenerator $urlGenerator,
53
        LoggerInterface $logger,
54
        Repo $repo,
55
        ISession $session,
56
        FormFactory $formFactory,
57
        IEventDispatcher $eventDispatcher,
58
        AssetManager $assetManager
59
    ) {
60
        parent::__construct(
61
            $flashService,
62
            $translator,
63
            $urlGenerator,
64
            $logger,
65
            $repo,
66
            $session,
67
            $formFactory,
68
            $eventDispatcher
69
        );
70
71
        $this->assetManager = $assetManager;
72
    }
73
74
    /**
75
     * @param string $entityId
76
     *
77
     * @return Entity
78
     */
79
    public function createEntity(string $entityId): IStringerEntity
80
    {
81
        $entity = new Entity($entityId, '', '', false);
82
83
        return $entity;
84
    }
85
86
    /**
87
     * @param IStringerEntity|null $entity
88
     *
89
     * @throws \League\Flysystem\FileNotFoundException
90
     */
91
    protected function addCustomAssets(?IStringerEntity $entity = null)
92
    {
93
        parent::addCustomAssets($entity);
94
95
        if (!($entity instanceof Entity)) {
96
            return;
97
        }
98
99
        $footer = $this->getResourceName(static::RESOURCE_FOOTER);
100
        $this->assetManager->addJs($footer, '/admin-assets/js/semi-auto.js');
101
    }
102
}
103