We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19726
    • 239 Posts
    I noticed that the sortorder of the TV’s in a template gets lost when I change a TV. For example I had my TV’s sorted for my standard template. Now I change one of the TV’s from "Text" to "Text area (mini)" and now the sortorder is not correct anymore.

    Is this behaviour expected when I change the TV or should I file a bug report for this?

    Seen on 0.9.6
      • 25663 MODX Staff
      • 12,272 Posts
      File a bug report please.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 10313
        • 375 Posts
        The same problem exists when I change the input option values (in my given case an @SELECT) of a TV. I just fixed an error and it seems that the TV I edited was set to the first (top) position.

        Martin
          • 19726
          • 239 Posts
          Reported: FS#926 (sorry for late reaction, been on holiday wink )
            • 5913
            • 42 Posts
            I also having the same issue in 0.9.6.1B, I looked into what would be causing this issue is in the save_tmplvars.processor.php in processors file and this happens on anytime you hit save in a template variable edit state. On line 132 it calls saveTemplateAccess() function which removes and then reinserts the id and its template (obviously removing its ranking position and putting it back at the top) not sure why this would be needed on an edit and if this line is removed it resolves this issue (but do so at your own discretion I am not liable smiley )

            I have added the same above into the bug report

            Looks like a quick fix
              • 5913
              • 42 Posts
              OK so I have been informed that by just removing the call to the function removes the ability to properly change templates. What was I thinking of course nothing is a quick fix lol smiley ok so I did some more research and came up with the following that restores the ability to change templates without changing the rank of the template variable.

              maybe this will solve it :0)

              I undid what I did above (back to the way it was) and then did the following below
              in the same file I did all my modifications inside the saveTemplateAccess() function.

              1. I added a global call to $modx (could have done it without but I thought why not) admin note: it is needed

              2. added the floowing lines below this line
              $tbl = "$dbase.`".$table_prefix."site_tmplvar_templates`";


              I added the following
              $getRankArrayKey = array();
              $getRankArrayValue = array();
              
              $getRank = $modx->db->select("templateid, rank", $tbl, "tmplvarid=$id");
              
              while( $row = $modx->db->getRow( $getRank ) ) {
              array_push($getRankArrayKey, $row[templateid]);
              array_push($getRankArrayValue, $row[rank]);
              }
              
              $getRankArray = array_combine($getRankArrayKey,$getRankArrayValue);


              3. I change the for loop to this

              for($i=0;$i<count($templates);$i++){
              $setRank = ($getRankArray[$templates[$i]])?$getRankArray[$templates[$i]]:0;
              mysql_query("INSERT INTO $tbl (tmplvarid,templateid,rank) VALUES($id,".$templates[$i].",$setRank);");
              }


              seems to have fixed the issue smiley

              let me know what you think (remember I am not a modx guru by any means and again this worked for me no promises smiley )
                • 25663 MODX Staff
                • 12,272 Posts
                Just to confirm this works great. Thank you. smiley
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 29635
                  • 361 Posts
                  Is it just me, or does this hack kill the ability to remove a TV from a template? ie. Once a TV is assigned to a template, it can’t be unassigned when this hack is present?

                  Or I could have botched the hack. If somebody could let me know it’d be great.
                    Need MODx Ecommerce? Try FoxyCart!