You are here

function opigno_learning_path_form_opigno_module_delete_form_alter in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x opigno_learning_path.module \opigno_learning_path_form_opigno_module_delete_form_alter()

Implements hook_form_FORM_ID_alter().

File

./opigno_learning_path.module, line 2304
Contains opigno_learning_path.module.

Code

function opigno_learning_path_form_opigno_module_delete_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Get the module entity object.
  $build_info = $form_state
    ->getBuildInfo();
  $module = $build_info['callback_object']
    ->getEntity();

  // Group content storage.
  $group_content_storage = Drupal::entityTypeManager()
    ->getStorage('group_content');
  $query = $group_content_storage
    ->getQuery();

  // Check if module related to at least one group.
  $gid = $query
    ->condition('entity_id', $module
    ->id())
    ->condition('type', [
    'group_content_type_162f6c7e7c4fa',
    'group_content_type_411cfb95b8271',
  ], 'IN')
    ->execute();

  // If it's exist as group content hide the delete button.
  if (!empty($gid)) {
    $form['description'] = [
      '#markup' => t('This module is being used and it needs to be removed from the trainings and/or courses using it before being able to delete it.'),
    ];
    unset($form['actions']['submit']);
  }
}