Completed
Push — master ( 999646...2d3371 )
by Craig
04:55
created

ConnectionsMenuEvent::addChild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula Foundation - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\ExtensionsModule\Event;
15
16
use Knp\Menu\ItemInterface;
17
use Symfony\Contracts\EventDispatcher\Event;
18
19
class ConnectionsMenuEvent extends Event
20
{
21
    /**
22
     * The full menu object
23
     *
24
     * @var ItemInterface
25
     */
26
    private $menu;
27
28
    /**
29
     * The name of the extension in use
30
     *
31
     * @var string
32
     */
33
    private $extensionName;
34
35
    public function __construct(ItemInterface $menu, string $extensionName)
36
    {
37
        $this->extensionName = $extensionName;
38
        $this->menu = $menu;
39
    }
40
41
    public function getExtensionName(): string
42
    {
43
        return $this->extensionName;
44
    }
45
46
    /**
47
     * Add a child menu item to the connections menu
48
     *
49
     * Returns this event object to allow method chaining
50
     *
51
     * @param ItemInterface|string $child   An ItemInterface instance or the name of a new item to create
52
     * @param array                $options If creating a new item, the options passed to the factory for the item
53
     *
54
     * @return $this
55
     */
56
    public function addChild($child, array $options = []): self
57
    {
58
        $this->menu->getChild('connections')->addChild($child, $options);
59
60
        return $this;
61
    }
62
}
63