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?