You are here

function opigno_file_upload_form_opigno_module_result_form_alter in Opigno module 8

Same name and namespace in other branches
  1. 3.x ActivityTypes/opigno_file_upload/opigno_file_upload.module \opigno_file_upload_form_opigno_module_result_form_alter()

Implements hook_form_BASE_FORM_ID_alter().

File

ActivityTypes/opigno_file_upload/opigno_file_upload.module, line 23
Contains opigno_file_upload.module.

Code

function opigno_file_upload_form_opigno_module_result_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $answers_id = array_filter(array_keys($form['answers']), 'is_int');
  foreach ($answers_id as $id) {
    $answer = OpignoAnswer::load($id);
    if (!is_null($answer)) {
      $activity = $answer
        ->getActivity();
      if (in_array($activity
        ->getType(), [
        'opigno_file_upload',
        'opigno_long_answer',
      ]) && $activity
        ->get('opigno_evaluation_method')
        ->getValue()[0]['value']) {
        if ($answer
          ->getType() == 'opigno_file_upload') {
          $owner = $answer
            ->getOwner();
          $user_link = Link::createFromRoute($owner
            ->getAccountName(), 'entity.user.canonical', [
            'user' => $owner
              ->id(),
          ])
            ->toString();
          $form['student'] = [
            '#type' => 'item',
            '#title' => t('Student\'s name: '),
            '#markup' => $user_link,
            '#weight' => -10,
          ];
        }
      }
    }
  }
}