public function LearningPathCreateMemberForm::buildForm in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/Form/LearningPathCreateMemberForm.php \Drupal\opigno_learning_path\Form\LearningPathCreateMemberForm::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/ LearningPathCreateMemberForm.php, line 24
Class
- LearningPathCreateMemberForm
- Members create form.
Namespace
Drupal\opigno_learning_path\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#prefix'] = '<div id="learning_path_create_member_form">';
$form['#suffix'] = '</div>';
$form['status_messages'] = [
'#type' => 'status_messages',
];
$group = $this
->getRequest()
->get('group');
$is_class = $group
->getGroupType()
->id() == 'opigno_class';
$args = [
'group' => $group !== NULL ? $group
->id() : 0,
];
$form['create_user'] = Link::createFromRoute($this
->t('Create new users'), 'opigno_learning_path.membership.create_user', $args)
->toRenderable();
$form['create_user']['#attributes']['class'][] = 'btn_create';
$form['create_user']['#attributes']['class'][] = 'use-ajax';
$form['create_user']['#attributes']['data-dialog-type'] = 'modal';
$form['create_user']['#attributes']['data-dialog-options'] = json_encode([
'dialogClass' => 'modal-dialog-sidebar',
]);
if (!$is_class) {
$form['create_class'] = Link::createFromRoute($this
->t('Create a new class'), 'opigno_learning_path.membership.create_class', $args)
->toRenderable();
$form['create_class']['#attributes']['class'][] = 'btn_create';
$form['create_class']['#attributes']['class'][] = 'use-ajax';
$form['create_class']['#attributes']['data-dialog-type'] = 'modal';
$form['create_class']['#attributes']['data-dialog-options'] = json_encode([
'dialogClass' => 'modal-dialog-sidebar',
]);
}
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$form['#attached']['library'][] = 'opigno_learning_path/create_member';
return $form;
}