Oct 3, 2012

Posted by in Drupal | 0 comments

How to add custom flag / bookmark in Drupal quiz module.

Drupal quiz, is a great module to be used, Flag is another module available in drupal which allowes us to flag (bookmark) any node, we often need to provide options for user to bookmark there question.

Flag module allows to bookmark a node, and it doesn’t work when we are using the quiz module to navigate through the questions and answers.

ex – sitename.com/node/2/take (would be the url to take a quiz, here by default we can’t have the bookmark (flag)

In order to achieve this we need to use the form hook. Put this code in any of your custom module, note to change “mymodule” in the function name to your module’s name.

ex – code

function mymodule_form_alter(&$form, &$form_state, $form_id) {
    if ($form_id == 'quiz_question_answering_form') { //id of the form
     $qnode_id = $form['question_nid']['#value'];
         //use flag api to create the link, here 'bookmarks' is the machine name for your flag.
     $linkb = flag_create_link('bookmarks', $qnode_id);  
     $form['navigation']['bookmark'] = array (
                                                                           '#type' => 'markup',
                                                                           '#value' => $linkb,
                                                                         );
  }
}

PS :: This solution is in Drupal 6, the same logic can be applied in Drupal 7 as well.

Leave a Reply