Completed
Push — master ( f8688a...e0c230 )
by Maxime
16s queued 11s
created

UiElementTrait::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of Monsieur Biz' Rich Editor plugin for Sylius.
5
 *
6
 * (c) Monsieur Biz <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace MonsieurBiz\SyliusRichEditorPlugin\UiElement;
15
16
use Symfony\Contracts\Translation\TranslatorInterface;
17
18
trait UiElementTrait
19
{
20
    /**
21
     * @var MetadataInterface
22
     */
23
    protected MetadataInterface $metadata;
24
25
    /**
26
     * @var TranslatorInterface
27
     */
28
    protected TranslatorInterface $translator;
29
30
    /**
31
     * @var bool
32
     */
33
    protected bool $ignored = false;
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function setMetadata(MetadataInterface $metadata): void
39
    {
40
        $this->metadata = $metadata;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function setTranslator(TranslatorInterface $translator): void
47
    {
48
        $this->translator = $translator;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getCode(): string
55
    {
56
        return $this->metadata->getCode();
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getAlias(): ?string
63
    {
64
        return $this->metadata->getAlias();
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function getTitle(): string
71
    {
72
        return $this->metadata->getParameter('title');
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function getDescription(): string
79
    {
80
        return $this->metadata->getParameter('description');
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function getIcon(): string
87
    {
88
        return $this->metadata->getParameter('icon');
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function getFormClass(): string
95
    {
96
        return $this->metadata->getClass('form');
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function getAdminFormTemplate(): string
103
    {
104
        return $this->metadata->getTemplate('admin_form');
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function getAdminRenderTemplate(): string
111
    {
112
        return $this->metadata->getTemplate('admin_render');
113
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118
    public function getFrontRenderTemplate(): string
119
    {
120
        return $this->metadata->getTemplate('front_render');
121
    }
122
123
    public function ignore(): void
124
    {
125
        $this->ignored = true;
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131
    public function jsonSerialize()
132
    {
133
        return [
134
            'code' => $this->getCode(),
135
            'description' => $this->translator->trans($this->getDescription()),
136
            'icon' => $this->getIcon(),
137
            'title' => $this->translator->trans($this->getTitle()),
138
            'ignored' => $this->ignored,
139
        ];
140
    }
141
}
142