On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Dear Modx users and developers!

    I’d like to answer the question above with MODx, and i haven’t figured out how to do this yet. My goal is to make a "frame", where simple managers (not the admin) can edit some TV’s of a document (let it be a container), but aren’t able to modify (or even see) them in the inherited pages’ settings.

    I’ve tried to solve this problem by using the Resource group + User group + Roles trio, and works fine, but there is a problem: A manager can modify the values of TVs in a container’s setup page, and all the values will be inheriting to the childs, but after that a manager is unable to see the child pages’ settings in the manager, because i prevented them to reach those pages by unchecking their box at the site’s access permission section.

    http://ysera.wplanet.hu/modx_inherit_1.jpg

    I’ve tried it with ManagerManager, without success:

    I. mm_hideFields(’tv7’, ’2’); // Hide the template variable "tv7" for users with role "2"

    Not an option, because if i hide a variable from a user with an exact role, it wouldn’t be able to reach this in the container ("frame") too.

    II. mm_hideFields(’alias’, ’1’, ’3’);
    // Hide the alias field for users with role "1" editing documents using template ID "3"

    Would be better, just unfortunately the container and the inherited resources are using the same template, that’s why the same ID. So i could get the same by using the option I.

    The solution would be preventing the manager to reach the TV’s on resources with an exact site ID, but i haven’t found the best way to accomplish this yet, and i can only hope there is a way to do this somehow.

    Thank you in advance, and sry for my english!

    Sincerely,
    Ysera



    • Quote from: ysera at Oct 13, 2009, 04:44 PM

      Would be better, just unfortunately the container and the inherited resources are using the same template, that’s why the same ID. So i could get the same by using the option I.

      Assign different template to containers, then hide descendant’s TVs with option II.
      • You can use PHP in your mm_rules chunk too. So you can do things like

        <?php //only to turn on highlighting
        
        // Hides the field tvname for all docs whose parent isn't id 28.
        if($content['parent'] != 28){
            mm_hideFields('tvname','2');
        }
        
        

        You could similarly apply rules if a user id or role was a particular value. Adding PHP to the mix you have little you can’t do given you think out the way to conditionally apply showing or hiding.
          Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. BlogTwitterLinkedInGitHub
        • Quote from: smashingred at Oct 13, 2009, 07:21 PM

          You can use PHP in your mm_rules chunk too. So you can do things like

          <?php //only to turn on highlighting
          
          // Hides the field tvname for all docs whose parent isn't id 28.
          if($content['parent'] != 28){
              mm_hideFields('tvname','2');
          }
          
          

          You could similarly apply rules if a user id or role was a particular value. Adding PHP to the mix you have little you can’t do given you think out the way to conditionally apply showing or hiding.

          Thank you!! laugh
          • Quote from: smashingred at Oct 13, 2009, 07:21 PM

            You can use PHP in your mm_rules chunk too.

            Supercool! I never noticed those global variable assignments before loading rules.

            Here is another ManagerManager example rule you could define:

            //<?php
            if (!empty($content['id'])) { // editing resource
              mm_hideFields("alias", $user_role);
            } else { // inserting new resource
              ...
            }
            
            • How to run this for more that one resource? Examplem below doesn’t work. Does anybody know why?

              if(($content['parent'] != 28) || ($content['parent'] != 29)) {
                  mm_hideFields('tvname','2');
              }
              


              parent 28
              child 1
              child 2
              parent 29
              child 3
              child 4
              • A switch statement should work, although I’m also having trouble getting it to work for negative values. If you wanted to hide that field if the parent WAS 28 or 29, then I’d suggest this:

                switch($content['parent']) {
                	case 28:
                	case 29:
                    	mm_hideFields('tvname','2');
                    	break;
                  	default:
                    	null;
                    	break;
                }


                But my PHP isn’t great, so I don’t know about ’if parent != 28 or 29’.

                Sorry!! Hopefully someone else might be able to show us what I expect is an easy fix!
                • After some trial and error, the blindingly obvious ended up working for me. It might not be the most elegant, nor ’right’ from a programmer’s point of view, but it does the job!

                  In my case, I wanted to hide a tv called ’image’ for everything apart from the child resources (28-34).

                  Grandparent2
                  Parent15
                  Child28
                  Child29
                  Child30
                  Parent16
                  Child31
                  Child32
                  Parent17
                  Child33
                  Child34

                  This worked for me:

                  switch($content['parent']) {
                  	case !15:
                  	case !16:
                  	case !17:
                  	case 2:
                      	mm_hideFields('image','!1');
                      	break;
                    	default:
                      	null;
                      	break;
                  }


                  Although I found I also needed to explicitly refer to the grandparent to make sure it the tv was hidden for the parents too.

                  Hope it might be of use to someone else.
                  • What other variables, other than $content[’parent’]
                    do we have that we can use to control what is displayed
                    or not in MM?
                      Website: www.mercologia.com
                      MODX Revo Tutorials:  www.modxperience.com

                      MODX Professional Partner
                    • Anybody found a way to control documents displayed under the ultimate parent rather than the nearest parent?