3

So I am trying to hide (or disable) a field in the "Edit Entry" view in the CP.

I know how to test a user group :
{% if currentUser.isInGroup('groupHandle') %}

But I cannot find a hook in Craft Doc to change the rendering of my field ? Perhaps with getInputHtml()? But I dont understand exactly how...

1

1 Answer 1

4

OK so here is my solution :
1/ define a custom permission for user groups

public function registerUserPermissions()
{
    return array(
        'updateTopNews' => array('label' => Craft::t('Update Top News')),
    );
}

2/ simply add css to hide the field when user has not the permission in my plugin init function

 public function init () {
    parent::init();

    $user = craft()->userSession->getUser();
    if ( craft()->request->isCpRequest() && $user ) {

        if ( !$user->can('updateTopNews') ) {
            craft()->templates->includeCss('#fields-topNews-field { display: none; }');
        }
    }
2
  • 2
    You better don't tell them, they can give themselves the "permission" with the web inspector tools. ;)
    – carlcs
    Commented Aug 14, 2015 at 5:14
  • Yeah dont worry my user are not tech savy no prob on that ! :) Commented Aug 14, 2015 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.