You are here

protected function UserRole::createRole in Feeds 8.3

Creates a new role with the given label and saves it.

Parameters

string $label: The label the new role should get.

Return value

int|string|false The ID of the new role or false if the given label is empty.

1 call to UserRole::createRole()
UserRole::findEntity in src/Feeds/Target/UserRole.php
Searches for an entity by entity key.

File

src/Feeds/Target/UserRole.php, line 134

Class

UserRole
Defines a user role mapper.

Namespace

Drupal\feeds\Feeds\Target

Code

protected function createRole($label) {
  if (!strlen(trim($label))) {
    return FALSE;
  }
  $values = [
    'id' => $this
      ->generateMachineName($label),
    'label' => $label,
  ];
  $entity = $this->entityTypeManager
    ->getStorage($this
    ->getEntityType())
    ->create($values);
  $entity
    ->save();
  return $entity
    ->id();
}