3

Trying to figure how to setup drupal 8 to function like StackExchange.

My goal is to be able to allow users to mark answers helpful so that best answers get moved to the top. Similar to StackExchange.

I can think of two ways to do this but would like some feedback from the experts.

Option 1: Create content Question and add comments to it. Use flag module to flag helpful replies. Create a template for question comments so that each top replies + its replies are groped together.

Option 2: Create Question, Create comment type Answer, Create a new comment type called replies and attach it to comment type Answer.

Or is there another alternative that I am not thinking off?

What would be the best way to create a similar setup such as StackExchange?

  • 2
    'Best' is a very vague term. Can you elaborate on what you mean? Performance, themeability, something else? Also option 2 appears to be an extension to option 1. I think you should not choose on what we think is best (question might get closed for being to opininated), you should choose on what your users need. Do you/they need comments on answers or not? – Neograph734 Aug 18 '17 at 20:59
  • 1
    Users need to comment in the answers. Basically, I am trying to setup similar functionality as StackExchange instead of setting up a forum thread style or a long string of comments. – Progonat Aug 18 '17 at 21:13
  • I am also looking for such functionality but there is no module for D8. – Umair Aug 20 '17 at 2:03
  • 1
    @Umair merci for the update. About Quiz module: that's like saying that questions (+ answers) on drupal.SE are quizes also, no? If you're looking for D7 based "inspiration" (the kind of functionality to consider), have a look at the Answers module ... all that's needed is a patch to upgrade it to D8 ... – Pierre.Vriens Aug 21 '17 at 12:13
  • 1
    @Pierre.Vriens and that patch can only be done by a person who knows how to that – Umair Aug 23 '17 at 11:13
1

Your Option 1 and Option 2 seem to both implement "answers" as comments...

Another option (= Option 3) would be to implement Answers as another content type, combined with an entity reference field (multiple values allowed) added to your Questions content type.

By using a content type for both Questions and Answers, it would probaby simplify anything about voting (either Question or Answers), and you could also use the Flag module (e.g. to mark "an" answer as the "accepted" answer).

At this time it's too early (= not ready for D8 yet) for some typical other modules that could be added to this later on:

  • the Rules module, to implement whatever logic you'd want (eg: only question authors can flag one, and only one. answer with the fag to mark an answer as accepted.
  • the Userpoints module, to implement your reputation system.

PS: you probaby have a good reason why it has to be implemented in D8, but if D7 would be "good enough" (at least for now), you could implement something similar to this Option 3 by using what is explained in this answer to "How to implement a reputation based system with badges in Drupal similar to StackExchange sites?".

  • Thank you for the suggestion. I was wondering if option three was possible as well. I think that would be the best way to go. If I understand you suggestion correctly. I create a content type Answers. Then add that as a field to Questions content type, add it as Reference Type > Content. Select multiple values. Here is what I am not clear about. Do I need to check allow reference if the entity does not exist? Or is there another way? – Progonat Aug 24 '17 at 12:39
  • @Progonat it seems that your understanding, as in your comment here is indeed correct. However, I'm not sure what to answer to your "Do I need to check allow reference if the entity does not exist?". Maybe you want to try to rephrase that by indicating what the "entity" actually would be (I think you mean "answer", but not sure. Also, why the setup/config of 2 content types (+ reference to multiple answers) you would have implemented a data moduel that I'd recommend. But know that you'll have to think of a UI to allow "new answers" only if linked to its related question (to avoid orphans). – Pierre.Vriens Aug 24 '17 at 12:55
  • Since comments are full entities in Drupal 8, there is no benefit of using a content type over a comment type.. You should be able to attach a flag to a comment just as good as you can attach it to a node. By choosing content types you invoke a lot more access checks and risk creating orphans. Besides you need modules like rabbit hole to prevent users from viewing the individual answers by their dedicated node id's. I would recommend to use comments. – Neograph734 Aug 30 '17 at 19:53
  • @Neograph734 DankJeWel (oeps: merci) for your comment. I agree that comments in D8 have a lot of improvements. Though "my" perception is that using another content type for "answers" (instead of comments as you suggested) simplifies things, at least for the Answers module. It may seem easy at first, but trust me, things can get pretty complicated.. The "questions" module does use such "comments"-approach for answers though. About the rabbit hole: have a look at what happens if you try to access this "answer" ... – Pierre.Vriens Aug 30 '17 at 20:16
  • @Pierre.Vriens, you will not get the demonstrated behavior by just using nodes and references ;-). (And rabbit hole certainly is not the only solution.) But there is no use in fighting over what would be the best solution, I just wanted to leave my thoughts on the matter. – Neograph734 Aug 30 '17 at 20:30

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.