suntrop

Add "Label" field to roles

Recommended Posts

I would like to use the label for roles, as the label is used for templates.

My role names are more technical and in englisch, but I would like to give them a more readable and lengthier name. When I edit the "role" template there is no field "templateLabel" I can add.

Share this post


Link to post
Share on other sites

Where do you need this "label" to be visible?

You could try adding a title field to the role template. This way, when you drill down the admin page-tree, you will see the title instead of the name.

  • Like 1

Share this post


Link to post
Share on other sites
13 minutes ago, dragan said:

Where do you need this "label" to be visible

On the user-edit page for example 

Share this post


Link to post
Share on other sites

I had added the title filed to the roles template. And I found I can configure the roles module to display other fields in the listing under Access > Roles – but currently I found no way to display the title instead the name on the user profile pages.

Share this post


Link to post
Share on other sites
1 hour ago, suntrop said:

but currently I found no way to display the title instead the name on the user profile pages.

What about this in your ready.php file:

$this->addHookBefore("InputfieldCheckboxes::render", function($event) {
    if($event->object->id != 'Inputfield_roles') return;
    $optionsWithTitles = array();
    foreach($event->object->options as $id => $name) {
        $roleTitle = $this->wire('roles')->get($id)->title;
        $optionsWithTitles[$id] = $roleTitle != '' ? $roleTitle . ' ('.$name.')' : $name;
    }
    $event->object->options = $optionsWithTitles;
});

 

In this screenshot I have only added a title to the "Editor" role:

59e102c57cfa9_ScreenShot2017-10-13at11_06_52AM.png.870ea20a7fccf219d132453af402277e.png

  • Like 5

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.