#3523351: Improved course student addition UI.
6 unresolved threads
6 unresolved threads
Closes #3523351
Merge request reports
Activity
- src/Access/LmsCustomAccess.php 0 → 100644
15 * LMS custom access methods. 16 */ 17 final class LmsCustomAccess implements ContainerInjectionInterface { 18 19 use AutowireTrait; 20 21 public function __construct( 22 private readonly AccountInterface $currentUser, 23 ) {} 24 25 /** 26 * Access to add a student to a class. 27 */ 28 public function addStudentAccess(Course $group): AccessResultInterface { 29 $result = AccessResult::forbidden(); 30 foreach ($group->getClasses() as $class) { - src/Form/AddStudentForm.php 0 → 100644
47 $class_options = []; 48 foreach ($group->getClasses() as $class) { 49 $class_options[$class->id()] = $class->label(); 50 } 51 52 $form['class'] = [ 53 '#type' => 'select', 54 '#title' => $this->t('Class'), 55 '#options' => $class_options, 56 ]; 57 58 $form['student'] = [ 59 '#type' => 'entity_autocomplete', 60 '#title' => $this->t('Student'), 61 '#target_type' => 'user', 62 '#selection_settings' => ['include_anonymous' => FALSE], - src/Form/AddStudentForm.php 0 → 100644
60 '#title' => $this->t('Student'), 61 '#target_type' => 'user', 62 '#selection_settings' => ['include_anonymous' => FALSE], 63 '#required' => TRUE, 64 ]; 65 66 $roles = $this->entityTypeManager->getStorage('group_role')->loadByProperties([ 67 'group_type' => 'lms_class', 68 'scope' => 'individual', 69 ]); 70 if (\count($roles) !== 0) { 71 $role_options = []; 72 foreach ($roles as $role) { 73 $role_options[$role->id()] = $role->label(); 74 } 75 $form['roles'] = [ changed this line in version 2 of the diff
- src/Form/AddStudentForm.php 0 → 100644
86 '#value' => $this->t('Add'), 87 ], 88 ]; 89 return $form; 90 } 91 92 /** 93 * {@inheritdoc} 94 */ 95 public function validateForm(array &$form, FormStateInterface $form_state): void { 96 /** @var \Drupal\group\Entity\GroupInterface */ 97 $class = $this->entityTypeManager->getStorage('group')->load($form_state->getValue('class')); 98 /** @var \Drupal\user\UserInterface */ 99 $student = $this->entityTypeManager->getStorage('user')->load($form_state->getValue('student')); 100 if ($class->getMember($student) !== FALSE) { 101 $form_state->setError($form['student'], $this->t('@student is already a member of the @class.', [ - src/Form/AddStudentForm.php 0 → 100644
101 $form_state->setError($form['student'], $this->t('@student is already a member of the @class.', [ 102 '@student' => $student->label(), 103 '@class' => $class->label(), 104 ])); 105 } 106 } 107 108 /** 109 * {@inheritdoc} 110 */ 111 public function submitForm(array &$form, FormStateInterface $form_state): void { 112 /** @var \Drupal\group\Entity\GroupInterface */ 113 $class = $this->entityTypeManager->getStorage('group')->load($form_state->getValue('class')); 114 /** @var \Drupal\user\UserInterface */ 115 $student = $this->entityTypeManager->getStorage('user')->load($form_state->getValue('student')); 116 $roles = \array_filter($form_state->getValue('roles') ?? []); changed this line in version 2 of the diff
56 54 _title_callback: '\Drupal\lms\Controller\CourseController::resultsTitle' 57 55 requirements: 58 56 _entity_access: 'group.results' 59 _entity_bundles: 'group:lms_course'
Please register or sign in to reply