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

ElementIndexesController::fieldId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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