2

Background

I am creating online courses, where groups of students work together giving answers to questions and commenting on each others answer.

I'm using Drupal 8, probably with Panels.

Challenge

I will have a content type called “Question”, created by the course creator.

The page for each Question should have:

  • the content of the Question, followed by
  • a list of (some of) the “Answers” from other students, showing the students name, the text of their Answer, a count of how many comments from other students the answer got, and a "show comments" link that shows the comments and offers a form for a new comment
    • a “new Answer” form where students can post their own Answer to the Question

Possible routes

I can see 2 ways to achieve this:

A: Treat top-level comments as "Answers"

AFAIK comments can be threaded, so I could treat the top-level comments as "Answers" and lower-level comments as "Comments". I could use a custom view block to only show the top-level comments on the “Question” page.

In this case, how would I enable the full text of the Answer and its child comments (the comments on the “Answer”) to show up (by AJAX or on a different page) when the reader clicked “show comments” on an answer?

B: Have “Answers” be a content type

The Answers content type would have an entity reference field “Question” that holds a reference to the parent Question.

This works well, but how would I insert a “new Answer” form which automatically and invisibly prepopulated the "Question" entity reference field with the id of the current Question?

Possible solutions seem to include

  • using the module formblock, which has a D8 port
  • porting the module entityreference_current to D8.
  • Creating a view that returns only the current Question id (by using Views contextual filters), having that view as the source for the entity reference field on an entityform, and finding some way to hide the field. This approach I found here: Reference to parent node on entity form type. This looks good and simple - any drawbacks?

Am I understanding the options right? Is there a better/different way to achieve this? My impression is that Option B - a second content type - is more robust and flexible?

1 Answer 1

1

I would go with option B, as having answers as content types allows you to add other features like the Flag module for up-votes.
The automatic and invisible reference linking can be done with the Entityreference prepopulate module, once there is a Drupal 8 version. You could also port it yourself or make an equivalent custom module. The older Node Reference URL Widget module would even add a link to your Question node on the Create Answer page with the appropriate URL adjustment for the reference.

1
  • Thanks! i will go with Option B and report back here anything more I learn
    – Jonathan
    Aug 6, 2015 at 14:07

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.