1

I want logged in users to be able to post questions or answers using the Answers module "anonymously"... that is, to appear anonymous but actually still be logged in, be able to follow their post, etc.

Edit: I thought this module could already do this but am not finding any settings for it.

Using Answers 7.x-4.0-rc2

Criteria:

  • anonymous/not logged in users should not be able to post
  • I want to give users the option to post anonymously but default to show the author
  • if a user posts "anonymously", the post would have do something about their avatar

    • on a per-post basis
  • Our site is complex with many other features, such as blogging, so changing usernames isn't an option; we want their usernames to show up everywhere else

  • 1
    Do you want all users to appear anonymous, or do you want users to have the option to be anonymous? Is changing the usernames enough, or do you want everything to say "Anonymous"? – Patrick Kenny Sep 28 '17 at 17:11
  • 1
    may be just to "hide" the author would be sufficient. – pinueve Sep 28 '17 at 17:17
  • Yes, I think hiding the author and avatar would work if they choose to be anonymous, but then it would have to be replaced with something else saying "anonymous". – Christia Sep 28 '17 at 17:57
  • use a boolean field to let users to choose to appear as anonimous or not, and with a hook_preprocess function you evaluate boolean field and you display author-name or anonymous – pinueve Sep 28 '17 at 18:06
  • In node--answers.tpl.php Looking at line 100 <?php if ($display_submitted): ?> then looking at line 18 $display_submitted: Whether submission information should be displayed. Seems like this module already has this feature? – No Sssweat Sep 28 '17 at 20:31
2

To my knowledge, the Answers module (you know the drill .. Disclosure: I'm a co-maintainer) does not have such setting that you were looking for. However, by using the Rules module (also), you should be able to get this to work, as further detailed below ...

Step 1: Create a (blocked) user 'Somebody'

Create an extra user with a user name that will be shown instead of the user name that you want to appear anonymous. I decided to name such user "Somebody", and it was created with uid=68. Moreover, I decided to make it a blocked user (not to be used for any other purpose).

Step 2: Add a dedicated field to relevant content types

For every content type for which you want this facility to be available (e.g for types Question and Answer), add an extra field that an editor (author) of a node can use to indicate if the node should appear anonymous.

In my case I have a selection list field with machine name field_optionlist and which has 2 possible values, like so:

  • A (= Appear anonymous).
  • S (= Standard author display).

Step 3: Create a custom rule

Below is custom rule (in Rules export format) that will set the node author to "Somebody" (= the user name from Step 1) whenever value "A" is selected via the dedicated field from Step 2 (and whenever a node of type Question or Answer is saved):

{ "rules_optionally_hide_node_author" : {
    "LABEL" : "Optionally hide node author",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave" : [] },
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : {
              "answers_answer" : "answers_answer",
              "answers_question" : "answers_question"
            }
          }
        }
      },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_optionlist" } },
      { "data_is" : { "data" : [ "node:field-optionlist" ], "value" : "A" } }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : { "type" : "user", "id" : "68" },
          "PROVIDE" : { "entity_fetched" : { "user_fetched" : "Fetched user" } }
        }
      },
      { "data_set" : { "data" : [ "node:author" ], "value" : [ "user-fetched" ] } }
    ]
  }
}

Adapt the uid=68 value in the above rule to fit your dedicated user, and replace the machine name of field_optionlist to fit your case (prior to trying to import the above rule).

That's it ... at least to make it work in my setup.

Step 4: Extra refinements

For the sake of completeness, you should create a variation of this custom rule to set the node author to "current user" whenever the field value is different from "A".

Bonus feature ...

By using the above approach, and by using a user name like Wiki, you can implement logic that is pretty close to "wiki" questions / answers on SE-sites also. Because for those kinds of questions/answers the original author will not have any user points (like reputation) changes anymore for any upvotes or downvotes of such question or answer.

  • 2
    This is a creative zero code solution. – No Sssweat Sep 30 '17 at 9:40
  • @NoSssweat Merci for the comment, may I say "What else did you expect?" I trust you know I always try to Keep It Super Simple ... Also because it's way cheaper to buy some extra memory (or something like that) for the overhead of yet another rule to be enabled, as compared to hiring a developer (not to forget upgrading to future Drupal releass) ... – Pierre.Vriens Sep 30 '17 at 9:53
  • This looks very thorough. I will try it out and let you know if I have any issues! Thank you. – Christia Oct 2 '17 at 22:03
  • @Christia did you ever get a chance to try this out? If so, how did it go? – Pierre.Vriens Nov 2 '17 at 11:14
  • I haven't had a chance to try it yet, sorry. I reached the deadline for the website and had to cut requests. I may try it for a future website update however and let you know. – Christia Nov 2 '17 at 12:19
1

Have you tried setting user permissions and giving anonymous users access to create content using the Answers module?

  • My post explains that I don't want Anonymous users to post. I want logged in users to post anonymously. – Christia Sep 28 '17 at 17:56
  • 1
    My mistake. I would add a boolean field, 'Appear Anonymous', to the user profile page, and only if the field is selected change the value of the user name being outputted. – TreyeDesigns Sep 28 '17 at 18:09
  • That's a good idea too, however, I only want it to apply on a per-post basis. – Christia Sep 28 '17 at 18:10
  • 1
    I am not familiar with the Answers module, but I assume you can add custom fields for the post? – TreyeDesigns Sep 28 '17 at 18:11

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.