We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18174
    • 116 Posts
    Hi Bob
    I tested it on a different install (equal to the bugtracker example). TV truly attached to the template, same effect.
    I don't have any form customization rules defined.
      • 3749
      • 24,544 Posts
      Good catch. Definitely sounds like a bug.
        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
        • 18174
        • 116 Posts
        Quote from: BobRay at Aug 25, 2013, 04:22 PM
        Good catch. Definitely sounds like a bug.
        Hi Bob
        Is there anything I can do except to file a bug as I did in my 1st post? I just try to find out if I'm the only one with this problem. Since a month I'm in trouble with this and I don't know where to start searching or who else to ask.
        best regards
        manu
          • 3749
          • 24,544 Posts
          Can you post the code you're using to get the TV value in the plugin?
            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
            • 18174
            • 116 Posts
            Quote from: BobRay at Sep 03, 2013, 09:57 PM
            Can you post the code you're using to get the TV value in the plugin?
            With the code I placed at the bugtracker you can easily reproduce the bug:

            example plugin OnWebPageInit:
            $id = $modx->resourceIdentifier;
            $resource = $modx->getObject('modResource', $id ) ;
            $tv = $resource->getTVValue('myTV');

              • 3749
              • 24,544 Posts
              For workarounds, you could try this:

              $id = $modx->resourceIdentifier;
              $resource = $modx->getObject('modResource', $id, false ) ;
              $tv = $resource->getTVValue('myTV');


              I suspect that the resource object is coming from the cache and bringing along its TV values. Setting the cache flag to false as above might prevent that.


              Or (this almost has to work), you could get the modTemplateVarResource object directly:


              $id = $modx->resourceIdentifier;
              $tvId = 12;  // or whatever
              
              $tvr = $modx->getObject('modTemplateVarResource', array('tmplvarid' => $tvId, 'contentid' => $id));
              if ($tvr) {
                  $tv = $tvr->get('value');
              } else {
                 $tvObj = $modx->getObject('modTemplateVar', $tvId);
                  $tv = $tvObj->get('default_text');
              }
              


              This assumes that you can use the raw value of the TV. If not you'd need to call $tvObj->renderOutput();









                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
                • 18174
                • 116 Posts
                Hi Bob,

                the 1st workaround has no effect, shows the same result.
                The 2nd choice I adapted like this
                $id = $modx->resourceIdentifier;
                $tvId = 1;  // or whatever
                 
                $tvr = $modx->getObject('modTemplateVarResource', array('tmplvarid' => $tvId, 'contentid' => $id));
                if ($tvr) {
                  $tvObj = $modx->getObject('modTemplateVar', $tvId);
                  $tv = $tvObj->renderOutput($id);
                } else {
                  $tvObj = $modx->getObject('modTemplateVar', $tvId);
                  $tv = $tvObj->get('default_text');
                }
                I do need the rendered value of the TV because it could be inherited. As soon I place the renderOutput($id) method caching doesn't work proberly.
                When I set renderOutput() without parameter $id the result is a blank screen.
                  • 3749
                  • 24,544 Posts
                  That definitely sounds like a bug.

                  You could try:

                  $tv = $tvr->getOne('TemplateVar');
                  $output = $tv->process();


                  I don't think it will work, but it's worth a try.

                  Worst case, you could process the value of the TV yourself, borrowing the code from the TV class file.
                    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
                    • 18174
                    • 116 Posts
                    $tv = $tvr->getOne('TemplateVar');
                    $output = $tv->process();
                    has the same effect, returns the correct TV Value but faulty caching.

                    And copying the code from TV class file is probably beyond my possibilities as I don't have the slightest idea about the cache building mechanism.

                    I'm just irritated how this bug does not worry more people since update from 2.2.7 (I'm pretty sure), since every plugin driven or controlled by a TV should throw this error. At least the revoSSL plugin was downloaded 172 times. Is this an answer why people complain about a slow MODX Revo?
                      • 3749
                      • 24,544 Posts
                      Looking at the TV code, I think it would not solve your problem.

                      Here's something else to try if you're using the MODX default caching scheme. This will simply delete the cache file for that resource. Do it before you try to get the TV value.

                      /* get resource context and id */
                      $ctx = $resource->get('context_key');
                      $docId = $resource->get('id');
                      
                      /* set path to default cache file */
                      $path = MODX_CORE_PATH . 'cache/resource/' . $ctx . '/resources/' . $docId . '.cache.php';
                      
                      unlink($path);


                      If you're not using the default caching scheme, it would have to look like this:

                       
                          /* get resource context and id */
                          $ctx = $resource->get('context_key');
                          $docId = $resource->get('id');
                      
                          /* set path to default cache file */
                          $path = MODX_CORE_PATH . 'cache/resource/' . $ctx . '/resources/' . $docId . '.cache.php';
                      
                          $ck = $resource->getCacheKey();
                          $mgrCtx = $modx->context->get('key');
                          $cKey = str_replace($mgrCtx, $ctx, $ck);
                      
                          $modx->cacheManager->delete($cKey, array(
                               xPDO::OPT_CACHE_KEY => $modx->getOption('cache_resource_key', null, 'resource'),
                               xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_resource_handler', null,
                               $modx->getOption(xPDO::OPT_CACHE_HANDLER)),
                               xPDO::OPT_CACHE_FORMAT => (integer)$modx->getOption('cache_resource_format', null,
                               $modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP))
                               )
                           );
                           /* belt and suspender time */
                           unlink($path);
                      
                        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