diff --git a/question_types/quiz_question/quiz_question.core.inc b/question_types/quiz_question/quiz_question.core.inc index 20306ff..5c43b3c 100644 --- a/question_types/quiz_question/quiz_question.core.inc +++ b/question_types/quiz_question/quiz_question.core.inc @@ -236,13 +236,19 @@ abstract class QuizQuestion { )) ->execute(); - - // Save what quizzes this question belongs to. // @kludge the quiz nid/vid are still on the node if (!empty($this->node->quiz_nid)) { $this->saveRelationships($this->node->quiz_nid, $this->node->quiz_vid); } + + if (!empty($this->node->revision)) { + // @kludge strange way of redirecting, since we do not have access to + // $form(_state) here + unset($_GET['destination']); + unset($_REQUEST['edit']['destination']); + $_REQUEST['edit']['destination'] = "node/{$this->node->nid}/question-revision-actions"; + } } /** diff --git a/question_types/quiz_question/quiz_question.module b/question_types/quiz_question/quiz_question.module index f32d2a8..3a7ab1e 100644 --- a/question_types/quiz_question/quiz_question.module +++ b/question_types/quiz_question/quiz_question.module @@ -20,11 +20,12 @@ function quiz_question_help($path, $args) { */ function quiz_question_menu() { $items = array(); - $items['node/%/question-revision-actions'] = array( + $items['node/%node/question-revision-actions'] = array( 'title' => 'Revision actions', 'page callback' => 'drupal_get_form', 'page arguments' => array('quiz_question_revision_actions_form', 1), - 'access arguments' => array('manual quiz revisioning'), + 'access callback' => 'node_access', + 'access arguments' => array('update', 1), 'file' => 'quiz_question.pages.inc', 'type' => MENU_NORMAL_ITEM, ); diff --git a/question_types/quiz_question/quiz_question.pages.inc b/question_types/quiz_question/quiz_question.pages.inc index 5eba7de..bdea9f3 100644 --- a/question_types/quiz_question/quiz_question.pages.inc +++ b/question_types/quiz_question/quiz_question.pages.inc @@ -19,43 +19,55 @@ * @return * FAPI form array */ -function quiz_question_revision_actions_form($form, $form_state, $node) { - $efq = new EntityFieldQuery(); +function quiz_question_revision_actions_form($form, $form_state, $question_node) { + $efq = new EntityFieldQuery; + + // Find relationships that contain not the current version of this question. $result = $efq->entityCondition('entity_type', 'quiz_question_relationship') - ->propertyCondition('child_nid', $node->nid) + ->propertyCondition('child_nid', $question_node->nid) ->execute(); + $relationships = entity_load('quiz_question_relationship', array_keys($result['quiz_question_relationship'])); + $affected = array(); + foreach ($relationships as $relationship) { + $affected[$relationship->parent_nid] = $relationship->parent_nid; + } - $text = t('You have created a new revision of a question that belongs to %num quizzes. Choose what you want to do with the different quizzes.', array('%num' => count($relationships))); + $text = t('You have created a new revision of a question that belongs to %num quizzes. Choose what you want to do with the different quizzes.', array('%num' => count($affected))); $form['intro'] = array( '#markup' => $text, ); $form['question_node'] = array( '#type' => 'value', - '#value' => $node, + '#value' => $question_node, ); $form['quizzes'] = array(); // Create a form element for each quiz. foreach ($relationships as $relationship) { $quiz = node_load($relationship->parent_nid); - $answered = quiz_has_been_answered($quiz); + if (node_access('update', $quiz)) { + $answered = quiz_has_been_answered($quiz); - $form['quizzes']['#tree'] = TRUE; - $form['quizzes'][$quiz->nid]['revise'] = array( - '#type' => 'radios', - '#title' => check_plain($quiz->title) . ' - ' . ($answered ? t('answered') : t('unanswered')) . ', ' . ($quiz->status ? t('published') : t('unpublished')), - '#options' => array( - 'update' => t('Update'), - 'revise' => t('Create new revision'), - 'nothing' => t('Do nothing'), - ), - '#default_value' => ($answered ? 'revise' : 'update'), - ); - $form['quizzes'][$quiz->nid]['status'] = array( - '#type' => 'checkbox', - '#title' => $quiz->status ? t('Leave published') : t('Publish'), - '#default_value' => $quiz->status, - ); + $options = array(); + if (user_access('manual quiz revisioning')) { + $options['update'] = t('Update (no revision)'); + } + $options['revise'] = t('Create new revision'); + $options['nothing'] = t('Do nothing'); + + $form['quizzes']['#tree'] = TRUE; + $form['quizzes'][$quiz->nid]['revise'] = array( + '#type' => 'radios', + '#title' => check_plain($quiz->title) . ' - ' . ($answered ? t('answered') : t('unanswered')) . ', ' . ($quiz->status ? t('published') : t('unpublished')), + '#options' => $options, + '#default_value' => ($answered ? 'nothing' : 'update'), + ); + $form['quizzes'][$quiz->nid]['status'] = array( + '#type' => 'checkbox', + '#title' => $quiz->status ? t('Leave published') : t('Publish'), + '#default_value' => $quiz->status, + ); + } } $form['submit'] = array(