0

I would like a list of all custom roles. Currently I am loading all of them using

$roles = $this->entityManager->getStorage('user_role')->loadMultiple();

but am wondering if there is any function that only brings the custom ones besides manually creating a static filter for the Anonymous, Authenticated and Administrator.

2
  • 3
    The Role entity doesn't really make any distinction. Looking at the roles in my own db (filter config table by name LIKE user.role%) the only potential contender I can see is that the three default ones have a dependency on _core, so you could check that via getDependencies, but that feels arguably flakier than a static filter to me. Mar 16, 2020 at 14:25
  • I see, thank you for clarifying that :-)
    – Lia
    Mar 18, 2020 at 7:17

1 Answer 1

0

As @stevekeiretsu said in a comment ->

The Role entity doesn't really make any distinction. Looking at the roles in my own db (filter config table by name LIKE user.role%) the only potential contender I can see is that the three default ones have a dependency on _core, so you could check that via getDependencies, but that feels arguably flakier than a static filter to me.

So for Drupal 8 there is no function defined.

Your Answer

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

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