You are here

public function AddRoleToUser::getSettingsForm in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/BusinessRulesAction/AddRoleToUser.php \Drupal\business_rules\Plugin\BusinessRulesAction\AddRoleToUser::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/BusinessRulesAction/AddRoleToUser.php, line 30

Class

AddRoleToUser
Class AddRoleToUser.

Namespace

Drupal\business_rules\Plugin\BusinessRulesAction

Code

public function getSettingsForm(array &$form, FormStateInterface $form_state, ItemInterface $item) {
  $settings['user_container'] = [
    '#type' => 'select',
    '#title' => t('User container'),
    '#default_value' => $item
      ->getSettings('user_container'),
    '#options' => [
      'current' => t('Current user'),
      'by_id' => t('By user id'),
      'variable' => t('User variable'),
    ],
  ];
  $settings['uid'] = [
    '#type' => 'textfield',
    '#title' => t('User id'),
    '#default_value' => $item
      ->getSettings('uid'),
    '#description' => t('You can use variables here.'),
    '#states' => [
      'visible' => [
        'select[name="user_container"]' => [
          'value' => 'by_id',
        ],
      ],
    ],
  ];
  $settings['variable'] = [
    '#type' => 'select',
    '#title' => t('User variable'),
    '#default_option' => $item
      ->getSettings('variable'),
    '#description' => t('The variable containing the user. Only variables type: "User variable".'),
    '#options' => $this->util
      ->getVariablesOptions([
      'user_variable',
    ]),
    '#states' => [
      'visible' => [
        'select[name="user_container"]' => [
          'value' => 'variable',
        ],
      ],
    ],
  ];
  $settings['roles'] = [
    '#type' => 'checkboxes',
    '#title' => t('Roles'),
    '#required' => TRUE,
    '#options' => $this->util
      ->getUserRolesOptions(),
    '#default_value' => is_array($item
      ->getSettings('roles')) ? $item
      ->getSettings('roles') : [],
    '#description' => t('Roles to add.'),
  ];
  return $settings;
}