You are here

public function UserHasRole::getSettingsForm in Business Rules 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/BusinessRulesCondition/UserHasRole.php \Drupal\business_rules\Plugin\BusinessRulesCondition\UserHasRole::getSettingsForm()

Return the form array.

@internal param array $form

Parameters

array $form: The form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

\Drupal\business_rules\ItemInterface $item: The configured item.

Return value

array The render array for the settings form.

Overrides BusinessRulesItemPluginBase::getSettingsForm

File

src/Plugin/BusinessRulesCondition/UserHasRole.php, line 33

Class

UserHasRole
Class UserHasRole.

Namespace

Drupal\business_rules\Plugin\BusinessRulesCondition

Code

public function getSettingsForm(array &$form, FormStateInterface $form_state, ItemInterface $item) {
  $settings['roles'] = [
    '#type' => 'checkboxes',
    '#title' => t('Roles'),
    '#required' => TRUE,
    '#options' => $this->util
      ->getUserRolesOptions(),
    '#default_value' => is_array($item
      ->getSettings('roles')) ? $item
      ->getSettings('roles') : [],
  ];
  $settings['criteria'] = [
    '#type' => 'select',
    '#title' => t('Match criteria'),
    '#description' => t('The condition will check if current user has all selected roles or at least one role?'),
    '#required' => TRUE,
    '#default_value' => $item
      ->getSettings('criteria'),
    '#options' => [
      'all' => t('All roles'),
      'one' => t('At least one role'),
    ],
  ];
  return $settings;
}