We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 999
    • 67 Posts
    Hi,
    I’m trying to make a plugin that creates a directory named after the document id. So i attach my plugin on the OnDocFormSave event and
    this is my code.

    $d = $modx->documentObject[’id’];
    system("mkdir /home/1471/domains/deloudis.gr/html/assets/images/ImageLib/".$d);
    echo $d;


    the problem is that i dont get a return value from $modx->documentObject[’id’];
    Am i doing something wrong?
    Alex.
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: AlexKay at Jan 05, 2007, 08:29 AM

      Hi,
      I’m trying to make a plugin that creates a directory named after the document id. So i attach my plugin on the OnDocFormSave event and
      this is my code.

      $d = $modx->documentObject[’id’];
      system("mkdir /home/1471/domains/deloudis.gr/html/assets/images/ImageLib/".$d);
      echo $d;


      the problem is that i dont get a return value from $modx->documentObject[’id’];
      Am i doing something wrong?
      Alex.


      The document object is only available on pages that are being rendered and executed in the front-end. The manager knows of no such concept or variable.
        • 999
        • 67 Posts
        Ok so any suggestions? how can i find the properties of the document im editing in order to use them in my plugin as i described?
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: AlexKay at Jan 05, 2007, 09:20 AM

          Ok so any suggestions? how can i find the properties of the document im editing in order to use them in my plugin as i described?
          Right now, you must find the manager pages that deal with document content, figure out the variable names it uses and code away. There is no consistent API for customizing the manager at this time. In the not-too-distant future, manager pages will be constructed just like front-end pages, but until then there is no easy way to do this.
            • 999
            • 67 Posts
            ok, understood.
            Does any one the variable that holds the document id? or where to search, so i wont have to reverse engineer the whole manager?
            i stumbled across this problem, and my deadline is already dead rolleyes
              • 11975
              • 2,542 Posts
              Hi,

              you can catch the id of the new document with this line of code

              $d = $modx->event->params['id'];
              


              :-)

              P.S:
              Explanations

              in /processors/save.content....
              line 296

              		$modx->invokeEvent("OnDocFormSave",
              								array(
              									"mode"	=> "new",
              									"id"	=> $key
              								));
              


              in document.parser invokeEvent function

                 if (!empty ($extParams))
                                  $parameter= array_merge($parameter, $extParams);
              
                              // eval plugin
                              $this->evalPlugin($pluginCode, $parameter);
              



              and

                  function evalPlugin($pluginCode, $params) {
                      $etomite= $modx= & $this;
                      $modx->event->params= & $params;
              
                Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                • 999
                • 67 Posts
                Ahh yes!
                Thanks man you saved me. Do you know if the variables initialized in mutate_content.dynamic.php affect my plugin (onSaveForm etc?); Meaning can i find in my plugin the parent, or top document of my current document? the one im editing ? mutate_content.dynamic.php seems to know it.will it pass in my plugin?
                  • 11975
                  • 2,542 Posts
                  As the doc has been saved in db you should access every properties of the new document easily by using modx API.

                  :-)
                    Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                    • 999
                    • 67 Posts
                    Here is what im after: I need to create document->n relations in documents. Each document is a piece of furniture, each one having n images. So what i wanted to do is to automatically create a folder named after the document’s id.But not for all documents, just the one belonging to a specific parent folder i.e Furniture.

                    So i need to know the document’s parent to decide if i must create the folder. My plugin executes OnDocFormSave. Is this after the document has been saved? or exactly before? If its after its ok i guess i can use the Db Api to find what i want.

                    I will also need to create my type of Tv to create multi relations.
                      • 11975
                      • 2,542 Posts
                      The onDocFormSave happens after the doc has been saved.
                      The $id comes from mysql_insert_id().

                      :-)
                        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l