We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36786 ☆ A M B ☆
    • 209 Posts
    I am trying to move from Articles to GridClassKey and I have found a stumbling block in that Modx does not have a standard field for changing the createdby and publishedby fields in the standard resource type (or any but Articles children). Is there a way to do so? I am rather surprised this is not a standard available setting.

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

      Ben Morrison
      Hacking templates to pieces since 2003
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That has never been a standard field; that is one of the few features of Articles that I ever liked.
        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
        • 36786 ☆ A M B ☆
        • 209 Posts
        Oh shoot... that is a big issue. Perhaps a quest on guthub for Modx?
          Ben Morrison
          Hacking templates to pieces since 2003
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          I think you could add the field with a plugin. You would need to use two events, one to add the field on before form render, and one to modify the fields being saved to the database on before form save.

          I'm pretty sure that the Manager code has a select drop-down for users, you should be able to "borrow" that for your field.
          /core/model/modx/processors/security/user/getlist.class.php
          /manager/assets/modext/sections/security/user/list.js
          /manager/assets/modext/widgets/security/modx.grid.user.js
          /manager/templates/default/security/user/list.tpl

          And of course you could take a look at the Articles code and see how they do it.
            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
            • 28042 ☆ A M B ☆
            • 24,524 Posts
              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
              • 36786 ☆ A M B ☆
              • 209 Posts
              Thanks! Now I know what files (of so many) to look at for examples... too bad I have the programming skills of a gorilla but I will try.
                Ben Morrison
                Hacking templates to pieces since 2003
                • 4172
                • 5,888 Posts
                May be an easier way could be to create a listbox-TV with @SELECT @EVAL or @CHUNK - binding
                And have a plugin for onDocFormSave to syncronize the createdby-field with the value of the TV
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 36786 ☆ A M B ☆
                  • 209 Posts
                  That could be much easier, in fact I would expect it to.
                    Ben Morrison
                    Hacking templates to pieces since 2003
                    • 36786 ☆ A M B ☆
                    • 209 Posts
                    Ok so I created an @EVAL binding to run the Peoples snippet and return a list of active users and it works (modified frm a solution to create Articles categories like in WP):
                    @EVAL return $modx->runSnippet('Peoples',array('tpl'=>'peoplesTpl','outputSeparator'=>'||','active'=>'1'));


                    The peoplesTpl is as follows:
                    [[+fullname]]==[[+id]]


                    Can anyone guide me on the creation of the plugin to be run onDocFormSave to set the createdby setting for the resource to be what is selected in the Tv? I was able to piece together the following from documentation, but it just hangs when I try to save a resource:

                    switch ($modx->event->name) {
                        case 'onDocFormSave':
                        
                        	$created_by = $resource->getTVValue('setCreatedBy')
                        	
                    		if ($resource->get('createdby') != $created_by) {  
                    			$modx->resource->set('createdby', $created_by));
                    		}
                    	break;
                    }
                    
                    [ed. note: maroonlover last edited this post 12 years, 5 months ago.]
                      Ben Morrison
                      Hacking templates to pieces since 2003
                      • 4172
                      • 5,888 Posts
                      I think it should be:

                      switch ($modx->event->name) {
                          case 'OnDocFormSave':
                            
                              $created_by = $resource->getTVValue('setCreatedBy');
                                
                              if (!empty($created_by) && $resource->get('createdby') != $created_by) {
                                  $resource->set('createdby', $created_by);
                                  $resource->save();
                              }
                          break;
                      }
                      [ed. note: Bruno17 last edited this post 12 years, 5 months ago.]
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!