Passed
Pull Request — master (#62)
by Romain
05:52 queued 02:14
created

ListFormNotifications   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A doList() 0 11 4
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Domain\Event\Form\Service;
18
19
use CuyZ\Notiz\Domain\Event\Form\DispatchFormNotificationFinisher;
20
use CuyZ\Notiz\Service\Container;
21
use TYPO3\CMS\Core\SingletonInterface;
22
use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface;
23
24
class ListFormNotifications implements SingletonInterface
25
{
26
    /**
27
     * @var FormPersistenceManagerInterface
28
     */
29
    protected $formPersistenceManager;
30
31
    /**
32
     * Manual dependency injection.
33
     */
34
    public function __construct()
35
    {
36
        $this->formPersistenceManager = Container::get(FormPersistenceManagerInterface::class);
37
    }
38
39
    /**
40
     * Loops on every registered form definition and checks if it uses the
41
     * notification dispatch finisher. If it does, the identifier is fetched and
42
     * added to the list.
43
     *
44
     * @param array $parameters
45
     */
46
    public function doList(array &$parameters)
47
    {
48
        foreach ($this->formPersistenceManager->listForms() as $form) {
49
            $persistenceIdentifier = $form['persistenceIdentifier'];
50
            $formDefinition = $this->formPersistenceManager->load($persistenceIdentifier);
51
52
            foreach ($formDefinition['finishers'] as $finisher) {
53
                if ($finisher['identifier'] === DispatchFormNotificationFinisher::DISPATCH_NOTIFICATION) {
54
                    $parameters['items'][] = [
55
                        $formDefinition['label'] . ' (' . $persistenceIdentifier . ')',
56
                        $persistenceIdentifier,
57
                    ];
58
                }
59
            }
60
        }
61
    }
62
}
63