Completed
Branch develop (17e8cf)
by Nate
10:01
created

ElementIndexesController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 43
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 21 1
A sourceId() 0 4 1
A fieldId() 0 4 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://www.flipboxfactory.com/software/element-lists/license
6
 * @link       https://www.flipboxfactory.com/software/element-lists/
7
 */
8
9
namespace flipbox\craft\element\lists\controllers;
10
11
use Craft;
12
use craft\base\Element;
13
use craft\events\RegisterElementActionsEvent;
14
use flipbox\craft\element\lists\elements\actions\DissociateFromElementAction;
15
use yii\base\Event;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class ElementIndexesController extends \craft\controllers\ElementIndexesController
22
{
23
    /**
24
     * @inheritdoc
25
     */
26
    public function init()
27
    {
28
        Event::on(
29
            Element::class,
30
            Element::EVENT_REGISTER_ACTIONS,
31
            function (RegisterElementActionsEvent $event) {
32
                $event->actions = [
33
                    [
34
                        'type' => DissociateFromElementAction::class,
35
                        'sourceId' => $event->data['sourceId'] ?? null,
36
                        'fieldId' => $event->data['fieldId'] ?? null
37
                    ]
38
                ];
39
            },
40
            [
41
                'sourceId' => $this->sourceId(),
42
                'fieldId' => $this->fieldId()
43
            ]
44
        );
45
        parent::init();
46
    }
47
48
    /**
49
     * @return mixed
50
     */
51
    private function sourceId()
52
    {
53
        return Craft::$app->getRequest()->getParam('sourceId');
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    private function fieldId()
60
    {
61
        return Craft::$app->getRequest()->getParam('fieldId');
62
    }
63
}
64