Massive Actions

Plugins can use the core’s massive actions for its own itemtypes.

They just need to additionally define a hook in their init function (setup.php):


function plugin_init_example() {
   $PLUGIN_HOOKS['use_massive_action']['example'] = 1;

But they can also add specific massive actions to core’s itemtypes. First, in their hook.php file, they must declare a new definition into a plugin_pluginname_MassiveActions function, ex addition of new action for Computer:


function plugin_example_MassiveActions($type) {
   $actions = [];
   switch ($type) {
      case 'Computer' :
         $myclass      = PluginExampleExample;
         $action_key   = 'DoIt';
         $action_label = __("plugin_example_DoIt", 'example');
            = $action_label;

   return $actions;

Next, in the class defined int the definition, we can use the showMassiveActionsSubForm and processMassiveActionsForOneItemtype in the same way as core documentation for massive actions:


class PluginExampleExample extends CommonDBTM {

   static function showMassiveActionsSubForm(MassiveAction $ma) {

      switch ($ma->getAction()) {
         case 'DoIt':
            echo __("fill the input");
            echo Html::input('myinput');
            echo Html::submit(__('Do it'), array('name' => 'massiveaction'))."</span>";

            return true;
      return parent::showMassiveActionsSubForm($ma);

   static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item,
                                                       array $ids) {
      global $DB;

      switch ($ma->getAction()) {
         case 'DoIt' :
            $input = $ma->getInput();

            foreach ($ids as $id) {

               if ($item->getFromDB($id)
                   && $item->doIt($input)) {
                  $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
               } else {
                  $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                  $ma->addMessage(__("Something went wrong"));

      parent::processMassiveActionsForOneItemtype($ma, $item, $ids);

Creative Commons License