We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34193
    • 330 Posts
    I have been able to hide certain tv’s on the tv tab but I am also wanting to move the one tv I want my sub admins to be able edit on to the create/edit document tab I have tried setting the tv to visable with various containing panels but can’t find one that works.

    My first question is, is this possible and you can prob guess the second where do I need to be looking to work it out or how do I do it.
      • 28215
      • 4,149 Posts
      Quote from: peteedley at Feb 17, 2010, 07:53 AM

      I have been able to hide certain tv’s on the tv tab but I am also wanting to move the one tv I want my sub admins to be able edit on to the create/edit document tab I have tried setting the tv to visable with various containing panels but can’t find one that works.

      My first question is, is this possible and you can prob guess the second where do I need to be looking to work it out or how do I do it.

      Moving TVs outside of the TV panel is not supported by the MODx Revolution core at this time.

      I’m sure you could do it via a plugin, however.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 34193
        • 330 Posts
        OK thanks that saves me spending more time trying to do it in the core. I’ll see what I can figure on the plugin side any guidance from anyone on this would be great I’ll post my findings as I go along.
          • 34193
          • 330 Posts
          OK looking at using this http://svn.modxcms.com/docs/display/revolution/Adding+Custom+Fields+to+Manager+Forms
          Is this likely to be the best way.
            • 34193
            • 330 Posts
            OK starting to get somewhere

            this is what I have in my plugin so far.
            <?php
            /**
             * Register a form field to forms
             */
            
            switch ($modx->event->name) {
                case 'OnDocFormPrerender':
                    /* if you want to add custom scripts, css, etc, register them here */
                    break;
                case 'OnDocFormRender':
            
                    /* Get the TV */
                    $tv = $modx->getObject('modTemplateVar',array('name'=>'mp3file'));
            
                    $v = '';
                    if (isset($scriptProperties['resource'])) {
                        /* on the update screen, so set the value */
                        /* get the raw content of the TV */
                        $v = $tv->getValue($id);
                    }
                    /* now do the HTML */
                    $fields = '
            <div class="x-form-item x-tab-item">
                <label class="x-form-item-label">MP3 File</label>
                <div class="x-form-element" style="padding-left:205px;">
                    <input type="text" name="mp3_file" value="'.$v.'" class="x-form-text x-form-field" />
                </div>
            </div>
            ';
                    $modx->event->output($fields);
            break;
                case 'OnDocFormSave':
                    /* do processing logic here. */
                    $resource =& $scriptProperties['resource'];
                    $resource->set('mp3file',$_POST['mp3_file']);
                    $resource->save();
                    break;
            }
            return;
            ?>


            The first bit works on update the value of the TV is retrieved and put into the form. I can’t get the OnDocFormSave section to work.

            An additional complecations that I hadn’t thought about is that the tv is a file based tv and opens the built in file browser to create it’s value. Can someone point me in the direction to work out how to do this with the form field this code is generating.
              • 34193
              • 330 Posts
              OK getting some where, still have the problem of hooking the form element into the file browser though, but this will work for plain text entry,

              in the above code change
                  case 'OnDocFormSave':
                      /* do processing logic here. */
                      $resource =& $scriptProperties['resource'];
                      $resource->set('mp3file',$_POST['mp3_file']);
                      $resource->save();
                      break;
              }
              return;


              To

              $doc = $modx->getObject('modDocument',$resource->get('id'));
              
              $tv = $modx->getObject('modTemplateVar', array('name' => 'mp3file'));
              $tv->setValue($doc->get('id'), $_POST['mp3_file']);
              $tv->save();
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: peteedley at Feb 23, 2010, 03:17 PM

                $doc = $modx->getObject('modDocument',$resource->get('id'));
                
                $tv = $modx->getObject('modTemplateVar', array('name' => 'mp3file'));
                $tv->setValue($doc->get('id'), $_POST['mp3_file']);
                $tv->save();

                Get rid of the $doc call, it is unnecessary as you already have $resource, e.g. $resource->get(’id’)