|
21 | 21 | use craft\events\RegisterElementActionsEvent; |
22 | 22 | use craft\events\RegisterUserPermissionsEvent; |
23 | 23 | use craft\services\UserPermissions; |
| 24 | +use craft\web\Application; |
24 | 25 | use venveo\bulkedit\elements\actions\BulkEditElementAction; |
25 | 26 | use venveo\bulkedit\services\BulkEdit; |
26 | 27 | use yii\base\Event; |
@@ -78,50 +79,51 @@ public function init() |
78 | 79 | 'permissions' => $permissions |
79 | 80 | ]; |
80 | 81 | }); |
| 82 | + Craft::$app->on(Application::EVENT_INIT, function() { |
| 83 | + if (Craft::$app->request->isCpRequest) { |
| 84 | + if (Craft::$app->user->checkPermission(self::PERMISSION_BULKEDIT_ENTRIES)) { |
| 85 | + Event::on(Entry::class, Element::EVENT_REGISTER_ACTIONS, |
| 86 | + function (RegisterElementActionsEvent $event) { |
| 87 | + $event->actions[] = BulkEditElementAction::class; |
| 88 | + } |
| 89 | + ); |
| 90 | + } |
81 | 91 |
|
82 | | - if (Craft::$app->request->isCpRequest) { |
83 | | - if (Craft::$app->user->checkPermission(self::PERMISSION_BULKEDIT_ENTRIES)) { |
84 | | - Event::on(Entry::class, Element::EVENT_REGISTER_ACTIONS, |
85 | | - function(RegisterElementActionsEvent $event) { |
86 | | - $event->actions[] = BulkEditElementAction::class; |
87 | | - } |
88 | | - ); |
89 | | - } |
90 | | - |
91 | | - if (Craft::$app->user->checkPermission(self::PERMISSION_BULKEDIT_CATEGORIES)) { |
92 | | - Event::on(Category::class, Element::EVENT_REGISTER_ACTIONS, |
93 | | - function(RegisterElementActionsEvent $event) { |
94 | | - $event->actions[] = BulkEditElementAction::class; |
95 | | - } |
96 | | - ); |
97 | | - } |
98 | | - |
99 | | - if (Craft::$app->user->checkPermission(self::PERMISSION_BULKEDIT_ASSETS)) { |
100 | | - Event::on(Asset::class, Element::EVENT_REGISTER_ACTIONS, |
101 | | - function(RegisterElementActionsEvent $event) { |
102 | | - $event->actions[] = BulkEditElementAction::class; |
103 | | - } |
104 | | - ); |
105 | | - } |
| 92 | + if (Craft::$app->user->checkPermission(self::PERMISSION_BULKEDIT_CATEGORIES)) { |
| 93 | + Event::on(Category::class, Element::EVENT_REGISTER_ACTIONS, |
| 94 | + function (RegisterElementActionsEvent $event) { |
| 95 | + $event->actions[] = BulkEditElementAction::class; |
| 96 | + } |
| 97 | + ); |
| 98 | + } |
106 | 99 |
|
107 | | - if (Craft::$app->user->checkPermission(self::PERMISSION_BULKEDIT_USERS)) { |
108 | | - Event::on(User::class, Element::EVENT_REGISTER_ACTIONS, |
109 | | - function(RegisterElementActionsEvent $event) { |
110 | | - $event->actions[] = BulkEditElementAction::class; |
111 | | - } |
112 | | - ); |
113 | | - } |
| 100 | + if (Craft::$app->user->checkPermission(self::PERMISSION_BULKEDIT_ASSETS)) { |
| 101 | + Event::on(Asset::class, Element::EVENT_REGISTER_ACTIONS, |
| 102 | + function (RegisterElementActionsEvent $event) { |
| 103 | + $event->actions[] = BulkEditElementAction::class; |
| 104 | + } |
| 105 | + ); |
| 106 | + } |
114 | 107 |
|
115 | | - if (Craft::$app->user->checkPermission(self::PERMISSION_BULKEDIT_PRODUCTS)) { |
116 | | - if (Craft::$app->plugins->isPluginInstalled('commerce') && class_exists(Product::class)) { |
117 | | - Event::on(Product::class, Element::EVENT_REGISTER_ACTIONS, |
118 | | - function(RegisterElementActionsEvent $event) { |
| 108 | + if (Craft::$app->user->checkPermission(self::PERMISSION_BULKEDIT_USERS)) { |
| 109 | + Event::on(User::class, Element::EVENT_REGISTER_ACTIONS, |
| 110 | + function (RegisterElementActionsEvent $event) { |
119 | 111 | $event->actions[] = BulkEditElementAction::class; |
120 | 112 | } |
121 | 113 | ); |
122 | 114 | } |
| 115 | + |
| 116 | + if (Craft::$app->user->checkPermission(self::PERMISSION_BULKEDIT_PRODUCTS)) { |
| 117 | + if (Craft::$app->plugins->isPluginInstalled('commerce') && class_exists(Product::class)) { |
| 118 | + Event::on(Product::class, Element::EVENT_REGISTER_ACTIONS, |
| 119 | + function (RegisterElementActionsEvent $event) { |
| 120 | + $event->actions[] = BulkEditElementAction::class; |
| 121 | + } |
| 122 | + ); |
| 123 | + } |
| 124 | + } |
123 | 125 | } |
124 | | - } |
| 126 | + }); |
125 | 127 | } |
126 | 128 |
|
127 | 129 | /** |
|
0 commit comments