We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ☆ A M B ☆
    • 450 Posts
    I'm working on a plugin that responds to TV values and, when a new resource is created (under certain conditions), instantly creates certain child resources under that new resource.

    I want to explicitly set the values in certain fields (pagetitle, alias, template, published, searchable, etc.)

    My question is, do I need to explicitly set the values in ALL the fields? Are there ones I can safely skip, which will get default values? Are there fields I must explicitly set?

    I'm probably going to just do some experimenting, but I'm hoping someone can give me some good advice to get me started in the right direction.
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      $fields = array(
        'pagetitle' => 'Foo bar',
        'alias' => 'foo-bar',
        'content' => 'Fooooooo bar!'
      );
      
      $response = $modx->runProcessor('resource/create', $fields);
      if ($response->isError()) {
         return 'Oops!';
      } else {
        // Success!
      }
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 14883 ☆ A M B ☆
        • 450 Posts
        I can now verify that this works.

        I can also verify that if you put code like this into an OnDocFormSave plugin, and you aren't careful about checking your conditional statements, you can create A WHOLE LOT OF RECURSIVE RESOURCES VERY QUICKLY with this code! smiley
          • 39932
          • 483 Posts
          Quote from: jrotering at Feb 21, 2013, 01:52 PM
          I can also verify that if you put code like this into an OnDocFormSave plugin, and you aren't careful about checking your conditional statements, you can create A WHOLE LOT OF RECURSIVE RESOURCES VERY QUICKLY with this code! smiley

          Yuppers! I learned that one myself. I use API created documents quite extensively.
            Website: Extended Dialog Development Blog: on Extended Dialog
            Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
            Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

            Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".