Jump to content

Add "Label" field to roles


suntrop
 Share

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.

Link to comment
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.

Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...