Skip to content
Snippets Groups Projects

#3522188: Conditionally hide the roles selector; unset roles if hidden selector value leaks.

Merged #3522188: Conditionally hide the roles selector; unset roles if hidden selector value leaks.
1 unresolved thread
Merged Marcin Grabias requested to merge issue/lms-3522188:3522188-course-roles-visible into 1.0.x
1 unresolved thread
2 files
+ 11
8
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -42,17 +42,12 @@ abstract class CourseMembershipHooksBase {
return;
}
// Roles selected - don't do anything.
$roles = $form_state->getValue('group_roles');
if (\is_array($roles) && \count(\array_filter($roles)) > 0) {
return;
}
$class_id = (string) $form_state->getValue('class');
if ($class_id === '' || $class_id === '0') {
return;
}
$form_state->setValue('group_roles', []);
$user_id = $form_state->getValue(['entity_id', '0', 'target_id']);
$potential_member = $this->entityTypeManager->getStorage('user')->load($user_id);
if ($course->isClassMember($potential_member)) {
@@ -89,6 +84,14 @@ abstract class CourseMembershipHooksBase {
'#description' => $self_join ? $this->t('You will be added to the selected class.') : $this->t('Student will be added to the selected class.'),
'#options' => $options,
];
if (\array_key_exists('group_roles', $form)) {
$form['group_roles']['#states'] = [
'visible' => [
'select[name=class]' => ['value' => '0'],
Please register or sign in to reply
],
];
}
}
/**
Loading