function opigno_learning_path_form_group_opigno_course_delete_form_alter in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 opigno_learning_path.module \opigno_learning_path_form_group_opigno_course_delete_form_alter()
Implements hook_form_FORM_ID_alter().
File
- ./
opigno_learning_path.module, line 2240 - Contains opigno_learning_path.module.
Code
function opigno_learning_path_form_group_opigno_course_delete_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Get the course entity object.
$build_info = $form_state
->getBuildInfo();
$course = $build_info['callback_object']
->getEntity();
// Group content storage.
$group_content_storage = Drupal::entityTypeManager()
->getStorage('group_content');
$query = $group_content_storage
->getQuery();
// Check if course related to at least one group.
$gid = $query
->condition('entity_id', $course
->id())
->condition('type', 'group_content_type_af9d804582e19')
->execute();
// If it's exist as group content hide the delete button.
if (!empty($gid)) {
$form['description'] = [
'#markup' => t('This course is being used and it needs to be removed from the trainings using it before being able to delete it.'),
];
unset($form['actions']['submit']);
}
}