Passed
Branch master (c87ba8)
by Christian
16:02
created

ListWidget::renderWidgetContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
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 List Widget implementation
24
 *
25
 * The widget will show a simple list with items provided by a data provider. You can add a button to the widget by
26
 * defining a button provider.
27
 *
28
 * There are no options available for this widget
29
 *
30
 * @see ListDataProviderInterface
31
 * @see ButtonProviderInterface
32
 */
33
class ListWidget implements WidgetInterface
34
{
35
    /**
36
     * @var WidgetConfigurationInterface
37
     */
38
    private $configuration;
39
40
    /**
41
     * @var StandaloneView
42
     */
43
    private $view;
44
45
    /**
46
     * @var array
47
     */
48
    private $options;
49
    /**
50
     * @var ButtonProviderInterface|null
51
     */
52
    private $buttonProvider;
53
54
    /**
55
     * @var ListDataProviderInterface
56
     */
57
    private $dataProvider;
58
59
    public function __construct(
60
        WidgetConfigurationInterface $configuration,
61
        ListDataProviderInterface $dataProvider,
62
        StandaloneView $view,
63
        $buttonProvider = null,
64
        array $options = []
65
    ) {
66
        $this->configuration = $configuration;
67
        $this->view = $view;
68
        $this->options = $options;
69
        $this->buttonProvider = $buttonProvider;
70
        $this->dataProvider = $dataProvider;
71
    }
72
73
    public function renderWidgetContent(): string
74
    {
75
        $this->view->setTemplate('Widget/ListWidget');
76
        $this->view->assignMultiple([
77
            'items' => $this->getItems(),
78
            'options' => $this->options,
79
            'button' => $this->buttonProvider,
80
            'configuration' => $this->configuration,
81
        ]);
82
        return $this->view->render();
83
    }
84
85
    protected function getItems(): array
86
    {
87
        return $this->dataProvider->getItems();
88
    }
89
}
90