You are here

public function OgRole::set in Organic groups 8

Sets the value of a property.

Parameters

string $property_name: The name of the property that should be set.

mixed $value: The value the property should be set to.

Return value

$this

Overrides ConfigEntityBase::set

5 calls to OgRole::set()
OgRole::setGroupBundle in src/Entity/OgRole.php
Sets the group bundle.
OgRole::setGroupType in src/Entity/OgRole.php
Sets the group type.
OgRole::setId in src/Entity/OgRole.php
Sets the ID of the role.
OgRole::setLabel in src/Entity/OgRole.php
Sets the label.
OgRole::setRoleType in src/Entity/OgRole.php
Sets the role type.

File

src/Entity/OgRole.php, line 224

Class

OgRole
Defines the OG user role entity class.

Namespace

Drupal\og\Entity

Code

public function set($property_name, $value) {

  // Prevent the ID, role type, group ID, group entity type or bundle from
  // being changed once they are set. These properties are required and
  // shouldn't be tampered with.
  $is_locked_property = in_array($property_name, [
    'id',
    'role_type',
    'group_id',
    'group_type',
    'group_bundle',
  ]);
  if (!$is_locked_property || $this
    ->isNew()) {
    return parent::set($property_name, $value);
  }
  if ($this
    ->get($property_name) == $value) {

    // Locked property hasn't changed, so we can return early.
    return $this;
  }
  throw new OgRoleException("The {$property_name} cannot be changed.");
}