You are here

public function RoleExpireApiService::setDefaultDuration in Role Expire 8

Same name and namespace in other branches
  1. 2.x 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();
  }
}