|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://github.com/flipboxfactory/craft-element-lists/LICENSE |
|
6
|
|
|
* @link https://github.com/flipboxfactory/craft-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 craft\events\RegisterElementSortOptionsEvent; |
|
15
|
|
|
use flipbox\craft\element\lists\ElementList; |
|
16
|
|
|
use flipbox\craft\element\lists\elements\actions\DissociateFromElementAction; |
|
17
|
|
|
use yii\base\Event; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Flipbox Factory <[email protected]> |
|
21
|
|
|
* @since 1.0.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class ElementIndexesController extends \craft\controllers\ElementIndexesController |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @inheritdoc |
|
27
|
|
|
*/ |
|
28
|
|
|
public function init() |
|
29
|
|
|
{ |
|
30
|
|
|
Event::on( |
|
31
|
|
|
Element::class, |
|
32
|
|
|
Element::EVENT_REGISTER_ACTIONS, |
|
33
|
|
|
function (RegisterElementActionsEvent $event) { |
|
34
|
|
|
$event->actions = [ |
|
35
|
|
|
[ |
|
36
|
|
|
'type' => DissociateFromElementAction::class, |
|
37
|
|
|
'sourceId' => $event->data['sourceId'] ?? null, |
|
38
|
|
|
'fieldId' => $event->data['fieldId'] ?? null |
|
39
|
|
|
] |
|
40
|
|
|
]; |
|
41
|
|
|
}, |
|
42
|
|
|
[ |
|
43
|
|
|
'sourceId' => $this->sourceId(), |
|
44
|
|
|
'fieldId' => $this->fieldId() |
|
45
|
|
|
] |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
Event::on( |
|
49
|
|
|
Element::class, |
|
50
|
|
|
Element::EVENT_REGISTER_SORT_OPTIONS, |
|
51
|
|
|
function (RegisterElementSortOptionsEvent $event) { |
|
52
|
|
|
$event->sortOptions[] = [ |
|
53
|
|
|
'label' => ElementList::t('Field Order'), |
|
54
|
|
|
'attribute' => 'field', |
|
55
|
|
|
'orderBy' => 'elementlist.sortOrder' |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
parent::init(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return mixed |
|
65
|
|
|
*/ |
|
66
|
|
|
private function sourceId() |
|
67
|
|
|
{ |
|
68
|
|
|
return Craft::$app->getRequest()->getParam('sourceId'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return mixed |
|
73
|
|
|
*/ |
|
74
|
|
|
private function fieldId() |
|
75
|
|
|
{ |
|
76
|
|
|
return Craft::$app->getRequest()->getParam('fieldId'); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|