Completed
Push — ezp25376-fields_groups ( 9d3f9c...0439a5 )
by
unknown
27:31
created

SettingsFieldsGroupsList   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
dl 0
loc 33
wmc 4
lcom 0
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getGroups() 0 4 1
A getDefaultGroup() 0 4 1
1
<?php
2
/**
3
 * This file is part of the ezpublish-kernel package.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Publish\Core\Helper\FieldsGroups;
7
8
use Symfony\Component\Translation\TranslatorInterface;
9
10
/**
11
 * A fields groups list implementation based on settings (scalar values) injection.
12
 * Human-readable names are obtained using the translator, in the `ezplatform_fields_groups` domain.
13
 *
14
 * @internal meant to be instantiated by the DIC. Do not inherit from it or instantiate it manually.
15
 */
16
final class SettingsFieldsGroupsList implements FieldsGroupsList
17
{
18
    /** @var array */
19
    private $groups;
20
21
    /** @var string */
22
    private $defaultGroup;
23
    /**
24
     * @var \Symfony\Component\Translation\TranslatorInterface
25
     */
26
    private $translator;
27
28
    public function __construct(TranslatorInterface $translator, $defaultGroup, array $groups)
29
    {
30
        $translatedGroups = [];
31
        foreach ($groups as $groupIdentifier) {
32
            $translatedGroups[$groupIdentifier] = $translator->trans($groupIdentifier, [], 'ezplatform_fields_groups');
33
        }
34
        $this->groups = $translatedGroups;
35
        $this->defaultGroup = $defaultGroup;
36
        $this->translator = $translator;
37
    }
38
39
    public function getGroups()
40
    {
41
        return $this->groups;
42
    }
43
44
    public function getDefaultGroup()
45
    {
46
        return $this->defaultGroup;
47
    }
48
}
49