5

I would like users to be able to ask questions related to current page without going to another page as it works now in the Relevant Answers module. There is a related issue: http://drupal.org/node/1826492

I can create a custom block with form in it, and create new Question node on submit.

How can I link that new node to current page?

4
+50

In your custom block return your form like this.

global $user;
// You may need to get your path a different way here?
$original_path = implode('/', args());
// Just set the GET path to the path ^ from there.  The form_alter()
// will pick it up automatically for you on line 86 in relevant_answers.module.
$_GET['path'] = relevant_answers_compress_string($original_path);

$node = (object) array('type' => 'question', 'uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'language' => LANGUAGE_NONE);
$form = render(drupal_get_form('question_node_form', $node));

// Return your rendered form.
// You may need to do some stuff with redirecting if its not going to the right page after you submit.
return $form;

This is completely untested but should get you down the right path to solving your issue.

  • field_question_path path field can be added to a form if it is build from scratch: $form['field_question_path'][$langcode][0]['value']['#value'] = $original_path. Corresponding field will need to be updated on the node. – Bulat Mar 18 '13 at 10:17
4

Make sure your Question-content type as a field called "node_reference_field" with the EntityReference module.

Once that's done, you just need to make sure the nid of the current node is stored in this field. Since you're using a custom block with a generated form, it won't be that hard.
I suggest you try something like:

$node = node_load ($form_state['nid']);
$form['node_reference_field']['value'] = $node->nid;

I'm not sure about the coding, but with the EntityReference module, you aren't far from a solution.

  • Are you sure that this is how the "Relevant Answers" works? – Bulat Feb 21 '13 at 8:18
  • I don't see why not. You can link as many nodes as you like with the reference – Michiel Feb 21 '13 at 8:19
  • Ok, I see that this is a possible way to do this without "Relevant Answers", but I want a way to do this with "Relevant Answers". – Bulat Feb 21 '13 at 8:21
2

If I have correctly understood, you want to insert a block inside a node visualization. If so, I would suggest using the context module, you just have to insert the condition (usually the path of the content such as node/*) and set the reaction to block. You could then select you block and put it in one of the regions defined in your theme.

1

The Relevant Answers module is one of the (separated) add-on modules for the 7.x-3.x version of the Answers module.

In the most recent 7.x-4.x version of the Answers module, this module has been obsoleted and replaced by the Answers Best Answer sub-module, which allows for marking any of the answers to a specific question as the best (accepted) answer (to display the blue checkmarks to the left of each answer, and which is replaced by a green checkmark when an answer is marked as the best answer).

With that, out-of-the-Anwers-box, you can now post a (new) answer right below a question, using a form that is similar to creating a new node.

Disclosure: I'm a (co-)maintainer of this module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.