Passed
Push — master ( c43fa0...9560e0 )
by
unknown
25:03 queued 11:18
created

NumberWithIconWidget::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
namespace TYPO3\CMS\Dashboard\Widgets;
19
20
use TYPO3\CMS\Fluid\View\StandaloneView;
21
22
/**
23
 * Concrete Number with Icon implementation
24
 *
25
 * The widget will show widget with an icon, a number, a title and a subtitle. The number is provided by a data
26
 * provider.
27
 *
28
 * The following options are available during registration:
29
 * - icon           string        The icon-identifier of the icon that should be shown in the widget. You should
30
 *                                register your icon with the Icon API
31
 * - title          string        The main title that will be shown in the widget as an explanation of the shown number.
32
 *                                You can either enter a normal string or a translation string
33
 *                                (eg. LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.failedLogins.title)
34
 * - subtitle       string        The subtitle that will give some additional information about the number and title.
35
 *                                You can either enter a normal string or a translation string
36
 *                                (eg. LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.failedLogins.subtitle)
37
 *
38
 * @see NumberWithIconDataProviderInterface
39
 */
40
class NumberWithIconWidget implements WidgetInterface
41
{
42
    /**
43
     * @var WidgetConfigurationInterface
44
     */
45
    private $configuration;
46
    /**
47
     * @var StandaloneView
48
     */
49
    private $view;
50
    /**
51
     * @var array
52
     */
53
    private $options;
54
    /**
55
     * @var NumberWithIconDataProviderInterface
56
     */
57
    private $dataProvider;
58
59
    public function __construct(
60
        WidgetConfigurationInterface $configuration,
61
        NumberWithIconDataProviderInterface $dataProvider,
62
        StandaloneView $view,
63
        array $options = []
64
    ) {
65
        $this->configuration = $configuration;
66
        $this->view = $view;
67
        $this->options = $options;
68
        $this->dataProvider = $dataProvider;
69
    }
70
71
    /**
72
     * @inheritDoc
73
     */
74
    public function renderWidgetContent(): string
75
    {
76
        $this->view->setTemplate('Widget/NumberWithIconWidget');
77
        $this->view->assignMultiple([
78
            'icon' => $this->options['icon'],
79
            'title' => $this->options['title'],
80
            'subtitle' => $this->options['subtitle'],
81
            'number' => $this->dataProvider->getNumber(),
82
            'options' => $this->options,
83
            'configuration' => $this->configuration
84
        ]);
85
        return $this->view->render();
86
    }
87
88
    /**
89
     * @return array
90
     */
91
    public function getOptions(): array
92
    {
93
        return $this->options;
94
    }
95
}
96