public function RecipientsPlugin::getMembersForm in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 src/Plugin/LearningPathMembers/RecipientsPlugin.php \Drupal\opigno_learning_path\Plugin\LearningPathMembers\RecipientsPlugin::getMembersForm()
Get members form.
Parameters
array $form: Form array.
mixed $form_state: Form state.
mixed $current_user: User object.
Return value
mixed From.
Overrides LearningPathMembersPluginBase::getMembersForm
File
- src/
Plugin/ LearningPathMembers/ RecipientsPlugin.php, line 21
Class
- RecipientsPlugin
- Class RecipientsPlugin.
Namespace
Drupal\opigno_learning_path\Plugin\LearningPathMembersCode
public function getMembersForm(array &$form, FormStateInterface $form_state, User $current_user, bool $hide = FALSE) {
// Get the groups, this allows to filter the available users.
$show_all = $current_user
->hasPermission('message anyone regardless of groups');
$users = opigno_messaging_get_all_recipients($show_all);
$options = [];
foreach ($users as $user) {
$options[$user
->id()] = $user
->getDisplayName();
}
// Remove the current users from the list of users
// that once can send a message to.
if (isset($options[$current_user
->id()])) {
unset($options[$current_user
->id()]);
}
// Sort the users by name.
uasort($options, 'strcasecmp');
$form['users_to_send'] = [
'#title' => t('Select the users you want to send a message to'),
'#type' => 'entity_selector',
'#options' => $options,
'#weight' => -1,
'#multiple' => TRUE,
'#prefix' => $hide ? '<div id="users-to-send" class="hidden">' : '<div id="users-to-send">',
'#suffix' => '</div>',
];
}