We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44649
    • 68 Posts
    Hi is there a way to add custom bulk actions to Collections? I've had a dig through the forums/google but unable to find anything! Ideally I'd like to be able to change a tv value on multiple resources selected.

    Thanks!

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      I think the closest thing to that would be the Batcher extra, but I don't think it operates on Resource TV values.

      You could do it with a form (or a Custom Manager Page) and a custom snippet. The code to set the TV values is really simple. The user interface is the difficult part.


      Given an array or comma-separated list of Resource IDs, the ID of the TV, and the value you want in the TVs, this is all you need (off the top of my head -- untested):

      $resourceIds = array(4, 10, 23, 38);
      $tvId = 12;
      $value = 'some value';
      
      foreach($resourceIds as $resourceId) {
          $c = array(
              'tmplvarid' => $tvId, 
              'contentid' => $resourceId',
          );
          $tvr = $modx->getObject('modTemplateVarResource', $c);
          if ($tvr) {
              $tvr->set('value', $value);
              $tvr->save();
      
          }
      
      }
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 44649
        • 68 Posts
        Thanks for the info Bob, think I'm going to have to make my own custom CMP and emulate a WordPress plugin the clients migrating from... should be interesting!