You are here

public function OgRole::getName in Organic groups 8

Returns the role name.

A role's name consists of the portion of the ID after the group entity type ID and the group bundle ID.

Return value

string The role name.

Overrides OgRoleInterface::getName

2 calls to OgRole::getName()
OgRole::isRequired in src/Entity/OgRole.php
Returns if this is a default role which is required and cannot be deleted.
OgRole::save in src/Entity/OgRole.php
Saves an entity permanently.

File

src/Entity/OgRole.php, line 143

Class

OgRole
Defines the OG user role entity class.

Namespace

Drupal\og\Entity

Code

public function getName() {

  // If the name is not set yet, try to derive it from the ID.
  if (empty($this->name) && $this
    ->id() && $this
    ->getGroupType() && $this
    ->getGroupBundle()) {

    // Check if the ID matches the pattern '{entity type}-{bundle}-{name}'.
    $pattern = preg_quote("{$this->getGroupType()}-{$this->getGroupBundle()}-");
    preg_match("/{$pattern}(.+)/", $this
      ->id(), $matches);
    if (!empty($matches[1])) {
      $this
        ->setName($matches[1]);
    }
  }
  return $this
    ->get('name');
}