How change group access of element depending of a variable value

kouros91

Member
Hi.
I would like changing with php code form edit access group of an element depending of a value variable.
I would like too changing with php code "read only" value of a field element depending of a value variable.
How can i do to access to these properties ?
Thank you
Nicolas
 
That's not possible with the code as-is. I would have to add some additional code to the core, and provide a hook in the form PHP plugin, something like onElementCanUse, to allow custom code to be run to make decisions about per-element access control.

That's a couple of hours work to code and test.

-- hugh
 
This is one of those things where to even answer your question, I had to flesh out some code, just to make sure it would work. So I'm already halfway there. I'll get Robbie to quote you on finishing it off.

-- hugh
 
Hi Hugh. I've paid last week for the code. How do i do to have access to the new properties ? Thanks . Nicolas
 
I committed that code a few days ago:

https://github.com/Fabrik/fabrik/commit/07fd7bfe0bb18269618e9e5f8ac6de349d896f7b

You'll need to do a full github update to pick up the changes.

To use it, you'll need to add a form PHP plugin, select 'onElementCanUse' as the hook, and then write a little code which return false if the element should not be editable.

In this example, I'm setting element ID 33 to read only if the 'event' join (fab_main_test___event_raw) is 17.

Code:
// probably don't want to do this for a new record, as elements won't have value, unless they are defaults
if (!$formModel->isNewRecord()) {
   // figure out which element we are being called for
  $elementId = $elementModel->getId();
   // is the element ID the one we want to hide?
  if ($elementId == 33) {
     // for debug purposes, uncomment the next line to see what the form data is set to
    //var_dump($elementId, $formModel->data);exit;
    // in this example, if the "event" join element is set to 17, we want to hide "this" element
    if ($formModel->data['fab_main_test___event_raw'] == '17') {
      return false;
    }
  }
}
return true;

In this example, if the 'event' is 18, I'm checking to see if the user is in Access Level 3 ("Special"), and sets read only (returns false) if they aren't;

Code:
// probably don't want to do this for a new record, as elements won't have value, unless they are defaults
if (!$formModel->isNewRecord()) {
   // figure out which element we are being called for
  $elementId = $elementModel->getId();
   // is the element ID the one we want to hide?
  if ($elementId == 33) {
     // for debug purposes, uncomment the next line to see what the form data is set to
    //var_dump($elementId, $formModel->data);exit;
    // in this example, if the "event" join element is set to 19, we want to hide "this" element
    // if the user isn't in the "Special" level (3)
    if ($formModel->data['fab_main_test___event_raw'] == '18') {
      $levels = $this->user->getAuthorisedViewLevels();
       // uncomment the next line for some debug output of the current user's access levels etc.
      //var_dump($levels, $this->user);exit;
      // will return false if user is not in Viewing Access level 3 ("Special")
      return in_array(3, $levels);
    }
  }
}
return true;

If you need help with the exact code you need, give me the full details of what you are trying to achieve.

-- hugh
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top