You are here

public function RoleExpireApiService::setDefaultDuration in Role Expire 2.x

Same name and namespace in other branches
  1. 8 src/RoleExpireApiService.php \Drupal\role_expire\RoleExpireApiService::setDefaultDuration()

Insert or update the default expiry duration for a role.

Parameters

string $rid: Role ID.

string $duration: The strtotime-compatible duration string.

File

src/RoleExpireApiService.php, line 200

Class

RoleExpireApiService
Class RoleExpireApiService.

Namespace

Drupal\role_expire

Code

public function setDefaultDuration($rid, $duration) {
  if (!empty($duration)) {

    // Insert new default duration.
    $config = $this->config
      ->getEditable('role_expire.config');
    $values_raw = $config
      ->get('role_expire_default_duration_roles');
    $values = empty($values_raw) ? [] : $values_raw;
    $values[$rid] = Html::escape($duration);
    $config
      ->set('role_expire_default_duration_roles', $values)
      ->save();
  }
}