We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39583
    • 103 Posts
    When ever I add a document, its parent document always changes to a container when I specifically want NOT to be. So whenever I add a new one I have to go to the parent and uncheck the container checkbox in document settings.
    This is in revolution. Is there a way to prevent this behaviour, freeze the resource or something like that?

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

      --
      André
      • 3749
      • 24,544 Posts
      That was the default behavior in Evolution, but it wasn't true of Revo for a long time. There should be a System Setting for it, imo (maybe there is, but I couldn't find one).

      The only easy solution I can think of would be a plugin connected to OnDocFormSave that would prevent anything from being a container. I'm not sure it would work and it might not meet your needs, but here it is:


      <?php
      if ($resource->get('isfolder')) {
         $resource->set('isfolder', false);
         $resource->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
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        If you create the new resource elsewhere then drag it into the parent in the Tree, the parent's container flag is not triggered.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 39583
          • 103 Posts
          Quote from: BobRay at May 07, 2014, 04:35 PM
          That was the default behavior in Evolution, but it wasn't true of Revo for a long time. There should be a System Setting for it, imo (maybe there is, but I couldn't find one).

          The only easy solution I can think of would be a plugin connected to OnDocFormSave that would prevent anything from being a container. I'm not sure it would work and it might not meet your needs, but here it is:


          <!--?php
          if ($resource--->get('isfolder')) {
             $resource->set('isfolder', false);
             $resource->save();
          }
          


          Thanks for your answer BobRay.
          I can't get it to work. I also tried to check the doc id and if its the specific one I want set isfolder to false, but it doesn't work either. Any other ideas?
            --
            André
            • 3749
            • 24,544 Posts
            You're right. It doesn't work, and attaching it to OnBeforeDocFormSave doesn't work either.

            Maybe the change happens when the tree is redrawn rather than when the doc is saved.
              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
            • discuss.answer
              • 3749
              • 24,544 Posts
              The change is in the resource/create processor's afterSave() event.

              public function afterSave() {
                  $this->object->addLock();
                  $this->setParentToContainer();
                  $this->saveResourceGroups();
                  $this->checkIfSiteStart();
                  return parent::afterSave();
              }


              Since it's the parent's isfolder value that needs changing, the code should be (attached to OnDocFormSave):

              <?php
              if ($mode !== modSystemEvent::MODE_NEW) return;
              
              $parent = $resource->getOne('Parent');
              if ($parent) {
                 $parent->set('isfolder', false);
                 $parent->save();
              }


              I tested it and it works. Although the parent resource is still shown as a folder in the tree, its 'isfolder' field is not set so it's not a container. The plugin only executes for new docs, so you can still set the "Container" checkbox when updating an existing resource. [ed. note: BobRay last edited this post 12 years, 4 months ago.]
                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
                • 39583
                • 103 Posts
                Quote from: BobRay at May 19, 2014, 05:26 PM
                The change is in the resource/create processor's afterSave() event.

                public function afterSave() {
                    $this->object->addLock();
                    $this->setParentToContainer();
                    $this->saveResourceGroups();
                    $this->checkIfSiteStart();
                    return parent::afterSave();
                }


                Since it's the parent's isfolder value that needs changing, the code should be (attached to OnDocFormSave):

                <!--?php
                if ($mode !== modSystemEvent::MODE_NEW) return;
                
                $parent = $resource--->getOne('Parent');
                if ($parent) {
                   $parent->set('isfolder', false);
                   $parent->save();
                }


                I tested it and it works. Although the parent resource is still shown as a folder in the tree, its 'isfolder' field is not set so it's not a container. The plugin only executes for new docs, so you can still set the "Container" checkbox when updating an existing resource.

                Thanks BobRay, this work perfectly. smiley
                  --
                  André