You are here

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

Same name and namespace in other branches
  1. 8 modules/br_group/src/Plugin/BusinessRulesAction/AssignRoleToUserAction.php \Drupal\br_group\Plugin\BusinessRulesAction\AssignRoleToUserAction::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

modules/br_group/src/Plugin/BusinessRulesAction/AssignRoleToUserAction.php, line 36

Class

AssignRoleToUserAction
Class AssignRoleToUserAction.

Namespace

Drupal\br_group\Plugin\BusinessRulesAction

Code

public function getSettingsForm(array &$form, FormStateInterface $form_state, ItemInterface $item) {
  $settings['group_id'] = [
    '#type' => 'textfield',
    '#title' => t('Group Id'),
    '#required' => TRUE,
    '#description' => t('The group id. You may use variable or token to fill this information'),
    '#default_value' => $item
      ->getSettings('group_id'),
  ];
  $settings['role_id'] = [
    '#type' => 'textfield',
    '#title' => t('Role Machine name'),
    '#required' => TRUE,
    '#description' => t('The role machine name to assign to the user. You may use variable or token to fill this information'),
    '#default_value' => $item
      ->getSettings('role_id'),
  ];
  $settings['user_key'] = [
    '#type' => 'radios',
    '#title' => t('Key to select the user'),
    '#default_value' => $item
      ->getSettings('user_key') ?: 'username',
    '#options' => [
      'username' => t('User Name'),
      'userid' => t('User Id'),
    ],
  ];
  $settings['user_name'] = [
    '#type' => 'textfield',
    '#title' => t('User Name'),
    '#description' => t('The user name. You may use variable or token to fill this information'),
    '#default_value' => $item
      ->getSettings('user_name'),
    '#states' => [
      'visible' => [
        ':input[name="user_key"]' => [
          'value' => 'username',
        ],
      ],
    ],
  ];
  $settings['user_id'] = [
    '#type' => 'textfield',
    '#title' => t('User Id'),
    '#description' => t('The user id. You may use variable or token to fill this information'),
    '#default_value' => $item
      ->getSettings('user_id'),
    '#states' => [
      'visible' => [
        ':input[name="user_key"]' => [
          'value' => 'userid',
        ],
      ],
    ],
  ];
  return $settings;
}