currentUserField() and core User fields

Hello,

I was wondering if one of you can answer this question : why core user fields are not available for the currentUserField() formula ?

Is there a logical reason I am missing that explains this ?

Because, while digging in the code, we understand that one property was missing for core fields (calculation_visible) but it seems that other vardefs properties are involved.

For instance, we were looking on an easy way to set a field as readonly if you are not an admin. The admin field is a core user field. We are able to customize the sugarfield_is_admin.php file and include 

$dictionary['User']['fields']['is_admin']['calculation_visible']=true;
But another property is missing for this field : $def['studio']['related'].
Because is_admin is a important field, we don't want to play with the studio.related property that we currently don't understand. Is someone aware about this vardefs property ?
Many thanks for your help.
Fred

the code I am talking about : 
  • include/Expressions/Expression/Generic/CurrentUserFieldExpression.php
  • modules/ExpressionEngine/formulaHelper.php with cleanFields function used from getValidUserFields function
  • Hi  ,

    I haven't personally modified the vardefs of is_admin and cannot say for certain why it is not made available. To accomplish this use case in the past, here is what I did:

    1. Create a checkbox field in the Users module (e.g. administrator_check_c) with the following attributes:
      1. Calculated: $is_admin
      2. Make visible for calculations: checked
    2. In the read-only formula, I reference that new field:
      Fullscreen
      1
      2
      3
      4
      5
      not(
      currentUserField(
      $administrator_check_c
      )
      )
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Chris

  • Hello  , 

      approach is spot on, and it will set your field to read-only at a UI level. 

    However, if you're looking for a more robust solution, I would suggest creating a Role that sets specific fields to read-only and adding the relevant users to that role. This can be done without any code customization and restricts editing both at the UI and API levels.

    Let us know your thoughts!

    Cheers,
    André

  • Hi   and  ,

    this is what we did...but it's a pity to create a new field to duplicate the data contains in another field.

    I really don't get why core fields are not available.

    But many thanks for your feedback guys, really appreciate your disponibility.

    Regards,

    Fred