You are here

protected function LearningPathStepsController::failedStep in Opigno Learning path 8

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

Provide a default failed messages for the learning path.

Parameters

string $type:

bool $modal:

string $message:

Return value

mixed

3 calls to LearningPathStepsController::failedStep()
LearningPathStepsController::finish in src/Controller/LearningPathStepsController.php
Show the finish page and save the score.
LearningPathStepsController::nextStep in src/Controller/LearningPathStepsController.php
Redirect the user to the next step.
LearningPathStepsController::start in src/Controller/LearningPathStepsController.php
Start the learning path.

File

src/Controller/LearningPathStepsController.php, line 102

Class

LearningPathStepsController
Class LearningPathStepsController.

Namespace

Drupal\opigno_learning_path\Controller

Code

protected function failedStep($type, $modal = FALSE, $message = '') {
  switch ($type) {
    case 'no_first':
      $message = $this
        ->t('No first step assigned.');
      break;
    case 'no_url':
      $message = $this
        ->t('No URL for the first step.');
      break;
    case 'no_score':
      $message = $this
        ->t('No score provided');
      break;
    case 'passed':
      $message = $this
        ->t('You passed!');
      break;
    case 'failed':
      $message = $this
        ->t('You failed!');
      break;
  }
  if ($type !== 'none' && ($redirect = $this
    ->redirectToHome($message, $modal))) {
    return $redirect;
  }
  $content = [
    '#type' => 'html_tag',
    '#value' => $message,
    '#tag' => 'p',
  ];
  if ($modal) {
    return (new AjaxResponse())
      ->addCommand(new OpenModalDialogCommand('', $content));
  }
  else {
    return $content;
  }
}