We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46584
    • 29 Posts
    Many thanks sottwell,
    I hadn't spotted that specific guide; I think I need more coffee this morning smiley
      • 46584
      • 29 Posts
      Hi Bob,

      Just to let you know that your code to add resources to a resource group "Pubbed" worked great.

      I added the leaveGroup method so that when unpublished it removed the resource from the resource group.

      So my final code was

      <?php
      $groupId = 5; /* Important: Set to ID of 'Pubbed' Resource Group (shown in Security -> Resource Groups). */
      
      if (!$resource->get('published')) {
          /* Not published */
      	/* Make sure it's not already in the group */
      	if ($modx->getObject('modResourceGroupResource', array(
      			'document_group' => $groupId,
      			'document' => $resource->get('id')))) {
      		/* Already in group so remove */
      		$resource->leaveGroup($groupId);
      		return;
      	}
          return;
      }
      
      /* Published */
      /* Make sure it's not already in the group */
      if ($modx->getObject('modResourceGroupResource', array(
              'document_group' => $groupId,
              'document' => $resource->get('id')))) {
          /* Already in group */
          return;
      }
      $resource->joinGroup($groupId);
      


      And I also set it to trigger for OnDocPublished and OnDocUnPublished (in addition to OnDocFormSave) so it responded to the right click publishing toggle.


      Many thanks again for putting me on the right path

      regards

      Ian.
        • 3749
        • 24,544 Posts
        I'm glad I could help. Thanks for reporting back. smiley
          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