public function UserPointsTransactor::buildConfigurationForm in User Points 8
Provides a form for this transactor plugin settings.
The form provided by this method is displayed by the TransactionTypeForm when creating or editing the transaction type.
Parameters
array $form: The transaction type form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
array The form array.
Overrides TransactorBase::buildConfigurationForm
See also
\Drupal\transaction\Form\TransactionTypeFormBase
File
- src/
Plugin/ Transaction/ UserPointsTransactor.php, line 131
Class
- UserPointsTransactor
- Transactor for user points type transactions.
Namespace
Drupal\userpoints\Plugin\TransactionCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
/** @var \Drupal\transaction\TransactionTypeInterface $transaction_type */
$transaction_type = $form_state
->getFormObject()
->getEntity();
$transactor_settings = $transaction_type
->getPluginSettings();
// Applicable roles.
$roles = [];
foreach (Role::loadMultiple() as $role_id => $role_entity) {
if (!in_array($role_id, [
RoleInterface::ANONYMOUS_ID,
RoleInterface::AUTHENTICATED_ID,
])) {
$roles[$role_id] = $role_entity
->label();
}
}
asort($roles);
if (!count($roles)) {
$roles = [
'' => $this
->t('- None -'),
];
}
$form['roles'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Applicable user roles'),
'#description' => $this
->t('The user roles to which this type of points is applicable. Leave empty to apply to any existing role.'),
'#options' => $roles,
'#default_value' => isset($transactor_settings['roles']) ? explode(',', $transactor_settings['roles']) : [
'',
],
];
return parent::buildConfigurationForm($form, $form_state);
}