You are here

function _uc_role_get_choices in Ubercart 8.4

Gets available roles for granting on product purchase.

Parameters

array $exclude: A list of role ids to exclude from the list.

Return value

array An assoc array with key = rid and value = role name.

4 calls to _uc_role_get_choices()
FeatureSettingsForm::buildForm in uc_role/src/Form/FeatureSettingsForm.php
Form constructor.
RoleFeatureForm::buildForm in uc_role/src/Form/RoleFeatureForm.php
Form constructor.
uc_role_form_user_profile_form_alter in uc_role/uc_role.module
Implements hook_form_user_profile_form_alter().
uc_role_uc_store_status in uc_role/uc_role.module
Implements hook_uc_store_status().

File

uc_role/uc_role.module, line 431
Grants roles upon accepted payment of products.

Code

function _uc_role_get_choices(array $exclude = []) {
  $output = [];

  // Get roles from Drupal, excluding Anonymous and Authenticated.
  $roles = user_role_names(TRUE);
  unset($roles[AccountInterface::AUTHENTICATED_ROLE]);

  // User set specific roles that we must use?
  $selected = \Drupal::config('uc_role.settings')
    ->get('default_role_choices');

  // If there's none, or if none are checked, use all of em.
  $default = empty($selected) || array_sum($selected) == 0;
  foreach ($roles as $rid => $name) {
    if ($default || !empty($selected[$rid]) && !in_array($rid, $exclude)) {
      $output[$rid] = $roles[$rid];
    }
  }
  return $output;
}