modxmodx-revolutionmodx-templates

How to show user's context resourcelist only


MODX Revolution 2.2.10-pl Migx 2.6.8

I use this in a TV for my clients to be abble to choose a ressource :

{"field":"link1","caption":"Lien","inputTVtype":"resourcelist"}

The context of a user is defined with a user group context access. I've tried to tick the checkbox of the user usergroup in the TV, but if I do that the user is not abble to see th TV anymore.

Problem is that mys client can see every ressources of every contexts. I need him to only be abble to see the resourcelist of their context. Is there a way to do that ?


Solution

  • You could make a TV with custom @eval options and use that for your migx field. See here for an example and description; http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/bindings/eval-binding.

    First change your TV to this, basically just swapping out "inputTVtype" to "inputTV"

    {
        "field":"link1",
        "caption":"Lien",
        "inputTV":"yourCustomTv"
    }
    

    Step two is to create a snippet that finds the resources you want, this requires you to have some knowledge of PHP. Basically you need to find the resources and loop them, outputting a string that looks like a regular list values string (resourceId==name||resourceId==name||...)

    Step three is to create "yourCustomTv", and for the input options give it the @EVAL return $modx->runSnippet('yourSnippet');