Skip to content
Snippets Groups Projects
Commit d0ec1971 authored by Kevin Paxman's avatar Kevin Paxman
Browse files

Experimentation hour: add the start of a form to bulk register users

parent 07cf32e3
No related branches found
No related tags found
3 merge requests!297Feature/istwcms 5983 bulk account creation,!274Draft: ISTWCMS-5551: fixing office hours display,!260Feature/istwcms 5668 a5kulkar rename references to publications
<?php
namespace Drupal\uw_cfg_common\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\uw_cfg_common\UwPermissions\UwPermissions;
/**
* Form class for the content access form.
*/
class UwAddUsersForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'uw_add_users_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// The list of users this form.
$form['users'] = [
'#title' => 'WatIAM user ID(s) (maximum 8 characters per ID)',
'#description' => 'Enter a single WatIAM user ID, or multiple WatIAM user IDs, one per line.<br>You can use <a href="https://idm.uwaterloo.ca/search/" target="_blank">authenticated WatIAM search</a> if you don\'t know their user ID (will open a new window).',
'#type' => 'textarea',
'#required' => TRUE,
];
// The submit button.
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Create new account(s)'),
'#button_type' => 'primary',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// The permissions array that was submitted in the form.
$submitted_users = explode(PHP_EOL, $form_state->getValue('users'));
// Step through each of the submitted users to create if needed/possible,
// or show a message if not.
foreach ($submitted_users as $row_name => $submitted_user) {
$this->messenger()->addStatus($this->t('Normally something would happen here...'));
}
// Set the message that the users have been created.
$this->messenger()->addStatus($this->t('Finished creating users.'));
}
}
...@@ -450,3 +450,8 @@ uw_site_management.uw_menu_report_csv: ...@@ -450,3 +450,8 @@ uw_site_management.uw_menu_report_csv:
menu_name: uw-menu-site-management menu_name: uw-menu-site-management
route_name: uw_cfg_common.uw_menu_report_csv route_name: uw_cfg_common.uw_menu_report_csv
weight: 0 weight: 0
uw_site_management.uw_add_users:
title: 'Add UWaterloo user(s)'
menu_name: uw-menu-site-management
route_name: uw_add_users.form
weight: 0
...@@ -48,3 +48,10 @@ uw_cfg_common.uw_menu_report_csv: ...@@ -48,3 +48,10 @@ uw_cfg_common.uw_menu_report_csv:
_controller: \Drupal\uw_cfg_common\Controller\UwDownloadCsvController::uwMenuReport _controller: \Drupal\uw_cfg_common\Controller\UwDownloadCsvController::uwMenuReport
requirements: requirements:
_permission: 'view UW CSV reports' _permission: 'view UW CSV reports'
uw_add_users.form:
path: '/admin/add-uwaterloo-users'
defaults:
_title: 'Add UWaterloo User(s)'
_form: '\Drupal\uw_cfg_common\Form\UwAddUsersForm'
requirements:
_permission: 'administer users'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment