You are here

public function OpignoAnswerForm::backwardsNavigation in Opigno module 8

Same name and namespace in other branches
  1. 3.x src/Form/OpignoAnswerForm.php \Drupal\opigno_module\Form\OpignoAnswerForm::backwardsNavigation()

File

src/Form/OpignoAnswerForm.php, line 513

Class

OpignoAnswerForm
Form controller for Answer edit forms.

Namespace

Drupal\opigno_module\Form

Code

public function backwardsNavigation(array $form, FormStateInterface $form_state) {
  $entity =& $this->entity;
  $module = $entity
    ->getModule();
  $activity = $entity
    ->getActivity();
  $attempt = $module
    ->getModuleActiveAttempt($this
    ->currentUser());
  $activities = $module
    ->getModuleActivities();
  if (key($activities) != $activity
    ->id()) {

    // Set last activity only if current activity is not first.
    $attempt
      ->setLastActivity($activity);
    $attempt
      ->save();
  }
  $args = [
    'opigno_module' => $module
      ->id(),
  ];
  $current_group = \Drupal::routeMatch()
    ->getParameter('group');
  if ($current_group) {
    $args['group'] = $current_group
      ->id();
  }

  // Query param is used to detect if we used backwards navigation button.
  $form_state
    ->setRedirect('opigno_module.take_module', $args, [
    'query' => [
      'backwards' => TRUE,
    ],
  ]);
}