PageLayout::createEntity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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\PageLayout as Entity;
13
use AbterPhp\Website\Form\Factory\PageLayout as FormFactory;
14
use AbterPhp\Website\Orm\PageLayoutRepo as Repo;
15
use League\Flysystem\FilesystemException;
16
use Opulence\Events\Dispatchers\IEventDispatcher;
17
use Opulence\Routing\Urls\UrlGenerator;
18
use Opulence\Sessions\ISession;
19
use Psr\Log\LoggerInterface;
20
21
class PageLayout extends FormAbstract
22
{
23
    const ENTITY_PLURAL   = 'pageLayouts';
24
    const ENTITY_SINGULAR = 'pageLayout';
25
26
    const ENTITY_TITLE_SINGULAR = 'website:pageLayout';
27
    const ENTITY_TITLE_PLURAL   = 'website:pageLayouts';
28
29
    const ROUTING_PATH = 'page-layouts';
30
31
    /** @var AssetManager */
32
    protected $assetManager;
33
34
    /** @var string */
35
    protected $resource = 'page_layouts';
36
37
    /**
38
     * PageLayout constructor.
39
     *
40
     * @param FlashService     $flashService
41
     * @param LoggerInterface  $logger
42
     * @param ITranslator      $translator
43
     * @param UrlGenerator     $urlGenerator
44
     * @param Repo             $repo
45
     * @param ISession         $session
46
     * @param FormFactory      $formFactory
47
     * @param AssetManager     $assetManager
48
     * @param IEventDispatcher $eventDispatcher
49
     */
50
    public function __construct(
51
        FlashService $flashService,
52
        LoggerInterface $logger,
53
        ITranslator $translator,
54
        UrlGenerator $urlGenerator,
55
        Repo $repo,
56
        ISession $session,
57
        FormFactory $formFactory,
58
        AssetManager $assetManager,
59
        IEventDispatcher $eventDispatcher
60
    ) {
61
        parent::__construct(
62
            $flashService,
63
            $logger,
64
            $translator,
65
            $urlGenerator,
66
            $repo,
67
            $session,
68
            $formFactory,
69
            $eventDispatcher
70
        );
71
72
        $this->assetManager = $assetManager;
73
    }
74
75
    /**
76
     * @param string $entityId
77
     *
78
     * @return Entity
79
     */
80
    protected function createEntity(string $entityId): IStringerEntity
81
    {
82
        return new Entity($entityId, '', '', '', '', new Entity\Assets('', '', '', [], []));
83
    }
84
85
    /**
86
     * @param IStringerEntity|null $entity
87
     *
88
     * @throws FilesystemException
89
     */
90
    protected function addCustomAssets(?IStringerEntity $entity = null)
91
    {
92
        parent::addCustomAssets($entity);
93
94
        if (!($entity instanceof Entity)) {
95
            return;
96
        }
97
98
        $footer = $this->getResourceName(static::RESOURCE_FOOTER);
99
        $this->assetManager->addJs($footer, '/admin-assets/js/hideable-container.js');
100
        $this->assetManager->addJs($footer, '/admin-assets/js/semi-auto.js');
101
        $this->assetManager->addJs($footer, '/admin-assets/js/required.js');
102
        $this->assetManager->addJs($footer, '/admin-assets/js/validation.js');
103
    }
104
}
105