Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

An anonymous user cannot assign themselves a role. Drupal automatically assigns a user the role of 'Authenticated user'. You can alter the permissions of that role accordingly if that suits your needs. or you can use mymodule_entity_presave to assign role to the anonymous users.

use Drupal\Core\Entity\EntityInterface;

function mymodule_entity_presave(EntityInterface $entity)
    if ($entity->getEntityTypeId() == 'user') {
        $role = $entity->get('field_role')->value;
        if ($role) {
        }elseif ($role = \Drupal::request()->headers->get("role")) {


Example 1: add role to body
          "name": { "value": "fooBar" },
          "mail": { "value": "" },
          "pass": { "value": "secretSauce" },
          "field_role": { "value": "editor" }


Example 1: add role to header
  Content-type: application/json
  role: editor


Add new comment

Restricted HTML


Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.


Contact Us

All the content is FREE but I still need your help


Become a patreon