You are here

function template_preprocess_quiz_questions_browser_body in Quiz 8.4

Prepares variables for views exposed form templates.

Default template: quiz-questions-browser-body.html.twig.

Parameters

array $vars: An associative array containing:

  • form: A render element representing the form.

File

./quiz.module, line 555
Quiz Module

Code

function template_preprocess_quiz_questions_browser_body(&$vars) {
  $form =& $vars['form'];
  $rows = array();
  $full_options = array();
  foreach ($form['titles']['#options'] as $key => $value) {
    $full_options[$key] = $form['titles'][$key];
    $full_options[$key]['#title'] = '';
  }

  // We make the question rows
  foreach ($form['titles']['#options'] as $key => $value) {

    // Find nid and vid
    $matches = array();
    preg_match('/([0-9]+)-([0-9]+)/', $key, $matches);
    $quest_nid = $matches[1];
    $quest_vid = $matches[2];

    //Construnct row
    $row = array();
    $row[]['data'] = $full_options[$key];
    $row[]['data'] = l($value, "node/{$quest_nid}", array(
      'html' => TRUE,
      'query' => array(
        'destination' => current_path(),
      ),
      'attributes' => array(
        'target' => 'blank',
      ),
    ));
    $row[]['data'] = $form['types'][$key]['#value'];
    $row[]['data'] = $form['changed'][$key]['#value'];
    $row[]['data'] = $form['names'][$key]['#value'];
    $rows[] = $row;
  }

  //Theme table
  $vars['table'] = array(
    '#theme' => 'table',
    '#header' => array(),
    '#rows' => $rows,
  );
  if (count($form['titles']['#options']) == 0) {
    print t('No questions were found');
  }
}