You are here

protected static function LearningPathValidator::moduleValidate in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/LearningPathValidator.php \Drupal\opigno_learning_path\LearningPathValidator::moduleValidate()

Checks if module have at least one activity.

Parameters

\Drupal\opigno_module\Entity\OpignoModule $module: Opigno Module Entity.

int $redirect_step: Step to redirect.

Return value

bool Is module valid.

2 calls to LearningPathValidator::moduleValidate()
LearningPathValidator::courseValidate in src/LearningPathValidator.php
Checks if course has at least one module, and all modules are valid.
LearningPathValidator::stepsValidate in src/LearningPathValidator.php
Redirect user if one of learning path steps aren't completed.

File

src/LearningPathValidator.php, line 54

Class

LearningPathValidator
Class LearningPathValidator.

Namespace

Drupal\opigno_learning_path

Code

protected static function moduleValidate(OpignoModule $module, &$redirect_step) {
  $activities = $module
    ->getModuleActivities();
  $is_valid = !empty($activities);
  $moduleHandler = \Drupal::service('module_handler');

  // Add ability to create empty 'skills module' with enabled option 'Use all suitable activities from Opigno system'.
  if ($moduleHandler
    ->moduleExists('opigno_skills_system') && $module
    ->getSkillsActive() && $module
    ->getModuleSkillsGlobal()) {
    $is_valid = TRUE;
  }
  if (!$is_valid && ($redirect_step === NULL || $redirect_step >= 4)) {
    if ($module
      ->getSkillsActive()) {
      $is_valid = TRUE;
    }
    else {
      $redirect_step = 4;
      $messenger = \Drupal::messenger();
      $messenger
        ->addError(t('Please, add at least one activity to @module module!', [
        '@module' => $module
          ->label(),
      ]));
    }
  }
  return $is_valid;
}