summaryrefslogtreecommitdiffstats
path: root/application/forms/Config/General/ThemingConfigForm.php
blob: 54ef2b18c68e0e173f33de9046d04eeb6644b930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */

namespace Icinga\Forms\Config\General;

use Icinga\Application\Icinga;
use Icinga\Application\Logger;
use Icinga\Web\Form;
use Icinga\Web\StyleSheet;

/**
 * Configuration form for theming options
 *
 * This form is not used directly but as subform for the {@link GeneralConfigForm}.
 */
class ThemingConfigForm extends Form
{
    /**
     * {@inheritdoc}
     */
    public function init()
    {
        $this->setName('form_config_general_theming');
    }

    /**
     * {@inheritdoc}
     *
     * @return  $this
     */
    public function createElements(array $formData)
    {
        $themes = Icinga::app()->getThemes();
        $themes[StyleSheet::DEFAULT_THEME] .= ' (' . $this->translate('default') . ')';

        $this->addElement(
            'select',
            'themes_default',
            array(
                'description'   => $this->translate('The default theme', 'Form element description'),
                'disabled'      => count($themes) < 2 ? 'disabled' : null,
                'label'         => $this->translate('Default Theme', 'Form element label'),
                'multiOptions'  => $themes,
                'value'         => StyleSheet::DEFAULT_THEME
            )
        );

        $this->addElement(
            'checkbox',
            'themes_disabled',
            array(
                'description'   => $this->translate(
                    'Check this box for disallowing users to change the theme. If a default theme is set, it will be'
                    . ' used nonetheless',
                    'Form element description'
                ),
                'label'         => $this->translate('Users Can\'t Change Theme', 'Form element label')
            )
        );

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getValues($suppressArrayNotation = false)
    {
        $values = parent::getValues($suppressArrayNotation);
        if ($values['themes_default'] === '' || $values['themes_default'] === StyleSheet::DEFAULT_THEME) {
            $values['themes_default'] = null;
        }
        if (! $values['themes_disabled']) {
            $values['themes_disabled'] = null;
        }
        return $values;
    }
}