Skip to content
Snippets Groups Projects

#3523351: Improved course student addition UI.

Merged #3523351: Improved course student addition UI.
6 unresolved threads
Merged Marcin Grabias requested to merge issue/lms-3523351:3523351-improve-course-student into 1.0.x
6 unresolved threads

Closes #3523351

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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) {
  • Could we do this with a custom 'add students' group permission on courses, and then map it maybe?

    This would make it easier to factor out classes to a separate lms_class module in the future I think.

  • Yes, that'll be required. I'll do it in a separate issue though because it'll need to be implemented in the ClassPermissionCalculator (mapping from course permission to the class permission).

    Unfortunately it'll need an update hook to add that perm to all existing member roles.

  • Please register or sign in to reply
  • catch @catch started a thread on the diff
  • 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],
    • Thought a possible follow-up could be a selection handler that excludes current students (from all classes), but that might turn out to be confusing, so maybe not.

    • Please register or sign in to reply
  • 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'] = [
  • catch @catch started a thread on the diff
  • 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.', [
  • 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') ?? []);
  • catch @catch started a thread on 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'
  • Marcin Grabias added 1 commit

    added 1 commit

    Compare with previous version

  • Please register or sign in to reply
    Loading