public function LearningPathCreateClassForm::buildForm in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/Form/LearningPathCreateClassForm.php \Drupal\opigno_learning_path\Form\LearningPathCreateClassForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ LearningPathCreateClassForm.php, line 28
Class
- LearningPathCreateClassForm
- Members create form.
Namespace
Drupal\opigno_learning_path\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#prefix'] = '<div id="learning_path_create_class_form">';
$form['#suffix'] = '</div>';
$form['name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Give a name to the class'),
'#placeholder' => $this
->t('Enter the class name'),
];
$form['search_label'] = [
'#type' => 'label',
'#title' => $this
->t('Add learners to the class'),
];
$group = $this
->getRequest()
->get('group');
$form['search'] = [
'#type' => 'textfield',
'#autocomplete_route_name' => 'opigno_learning_path.membership.add_user_to_class_autocomplete',
'#autocomplete_route_parameters' => [
'group' => $group !== NULL ? $group
->id() : 0,
],
'#placeholder' => $this
->t('Search name or email'),
'#attributes' => [
'id' => 'class_users_autocomplete',
],
];
$form['new_class_users'] = [
'#type' => 'multiselect',
'#attributes' => [
'id' => 'new_class_users',
'class' => [
'row',
],
],
'#options' => [],
'#validated' => TRUE,
'#process' => [
[
'Drupal\\multiselect\\Element\\MultiSelect',
'processSelect',
],
],
'#prefix' => '<div id="learning_path_create_class_form_messages" class="alert-danger"></div>',
];
$form['create'] = [
'#type' => 'submit',
'#value' => $this
->t('Create new class'),
'#attributes' => [
'class' => [
'use-ajax',
'btn_create',
],
],
'#ajax' => [
'callback' => [
$this,
'submitFormAjax',
],
'event' => 'click',
],
];
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$form['#attached']['library'][] = 'opigno_learning_path/create_member';
return $form;
}