Is there a way to replace the "Anonymous" as the Topic starter in the forum topics list with the name user has stated when he/she created the topic using Anonymous Posting?

(I am not sure if this is an issue for Anonymous Posting or for Advanced Forum...)

Thanx,
Mat

Comments

drikc’s picture

Title: Forum topics created by anonymous have author as Anonymous » Topic list show the 'Anonymous' string instead of the author name with Advandced Form module

Just tried with Advanced Forum module and yes I can see that the 'Anonymous' string is shown instead of the recorded anonymous author name.

Certainly something can be done and if a part must be in Anonymous Posting module I will gladly do it, but as what I can see for now is that probably Advanced Forum (quickly went through the 3000 lines) will have to be adapted in somewhat.

I recommend that you post an issue to Advanced Forum module by including a link to this one.

drikc’s picture

Version: 7.x-1.0-beta4 » 7.x-1.x-dev
michelle’s picture

I haven't looked at this module but my best guess is its Views integration is what is at issue here since AF's topic list is a view. Not likely anything can be done on AF's end for this. If it turns out there is, move this issue; don't duplicate it.

Michelle

dreamingX’s picture

Thank you for the answers. I have come up to the same conclusion (to blame the Views) and even tried to change the view. It is possible to define special text for anyonymous users that is presented as the creator of the topic (i still was unable to add a token for 'name' that is used by AP though), but changing the column Last post doesn't include such an option. Since this column is only a problem until someone replies to the topic (either registered user or anonymous) I have decided to live with this. I guess with some preprocess function the first column could be solved. Any ideas?

drikc’s picture

Title: Topic list show the 'Anonymous' string instead of the author name with Advandced Form module » Topic list show the 'Anonymous' string instead of the author name with Advanced Forum module
msedlacek’s picture

any update on this?

lurkingbeast’s picture

Advanced Forum perhaps renders the username in a different way, but on a related note I had this same issue when using Display Suite.

To fix this I hacked the display suite module from

function ds_render_author_field($field) {

  // Users without a user name are anonymous users. These are never linked.
  if (empty($field['entity']->name)) {
    return check_plain(variable_get('anonymous', t('Anonymous')));
  }

to

function ds_render_author_field($field) {

  // Users without a user name are anonymous users. These are never linked.
  if (empty($field['entity']->name)) {
      if(empty($field['entity']->field_anonymous_author[LANGUAGE_NONE][0]['name'])) {
          return check_plain(variable_get('anonymous', t('Anonymous')));
      }
    return check_plain($field['entity']->field_anonymous_author[LANGUAGE_NONE][0]['name']); 
  }

nicorac’s picture

Hi guys, I'm experiencing the same issue so here's my cleaner fix.
It uses Views hook_views_pre_render hook to alter rendered data.
It must be added to your own module or template and doesn't hack other modules code.

// hook into view rendering process to replace "Anonymous"
// with the content of field_anonymous_author field
function YOURMODULENAME_views_pre_render(&$view) {

  // consider only the desired advanced_forum_topic_list view
  // excluding editing mode, to avoid confusion when using Views editor
  if($view->name == 'advanced_forum_topic_list' && $view->editing == 0) {

    // scan all result rows
    foreach($view->result as $row) {

      // test if post author is "Anonymous"
      if($row->users_node_uid == 0) {

        // retrieve anonymous user name from node field field_anonymous_author
        if(isset($row->_field_data['nid']['entity']->field_anonymous_author['und'][0]['name'])) {
          $row->users_node_name = $row->_field_data['nid']['entity']->field_anonymous_author['und'][0]['name'];
        }

      }

    }

  }

}

Hope this fix will be included into Anonymous Posting code.

nicorac’s picture

Category: support » feature
Status: Active » Needs review

Single function patch is into my previous post...

drikc’s picture

thanks nicorac,

I've pushed you code: http://drupalcode.org/project/anonymous_posting.git/commitdiff/8b49d3a?h... It will soon appear in the 7.x-1.x-dev release.

Btw, I didn't tested yet as I don't use myself Advanced Forum (I should now as your fix look very nice ;-)). Also, if someone else can report that it work it I would be nice; I will make a dedicated 1.1 release for it!

nicorac’s picture

I'd very much like to read other user's comments too.

The patch is running on my (small) forum that will be published here in a few days: http://coolsoft.altervista.org/forum
Your module is a godsend because my (small) forum is 99% anonymous (user support), then allow anonymous users to post is a must.

Thanks for your kindness

drikc’s picture

Hi, I've tested nicorac patch; works great! Also, I've added the substitution of the last contributor name with the anonymous user name if there is no comments for a topic; was displaying the 'Anonymous' string here also...

Nicorac or someone if you mind checking the last commits I will do a 1.1 release!

nicorac’s picture

Also, I've added the substitution of the last contributor name

Ouch..., I missed that part, thanks!
It works perfectly on my side, so I removed patch from my own module and will use your.

Cheers
Claudio

drikc’s picture

Status: Needs review » Fixed

Thanks, it's in 1.1!

nicorac’s picture

Status: Fixed » Needs review

Sadly just after the new release I saw something that should be changed.
We've been too conservative on our patch ;) : the same View patch should be applied to all of the Advanced Forums views, otherwise filtered views (like "Unanswered topics" and "Active topics") still show "Anonymous"...

See the new anonymous_posting_views_pre_render below

/**
 * Implements hook_views_pre_render().
 *
 * Hook into view rendering process to replace "Anonymous" with the content of
 * field_anonymous_author field.
 *
 */
function anonymous_posting_views_pre_render(&$view) {

  // consider only the desired advanced_forum_topic_list view
  // excluding editing mode, to avoid confusion when using Views editor
  $views = array(
      'advanced_forum_topic_list',
      'advanced_forum_active_topics',
      'advanced_forum_unanswered_topics',
      'advanced_forum_new_topics',
  );
  if($view->editing == 0 && in_array($view->name, $views)) {

    // scan all result rows
    foreach($view->result as $row) {

      // test if post author is "Anonymous"
      if($row->users_node_uid == 0) {

        // retrieve anonymous user name from node field field_anonymous_author
        if(isset($row->_field_data['nid']['entity']->{ANONYMOUS_POSTING_FIELD_NAME}['und'][0]['name'])) {
          $row->users_node_name = check_plain($row->_field_data['nid']['entity']->{ANONYMOUS_POSTING_FIELD_NAME}['und'][0]['name']);

          // set last comment name to anonymous user name  if there is no comments
          if (!$row->node_comment_statistics_comment_count) {
            $row->node_comment_statistics_last_comment_name = $row->users_node_name;
          }

        }

      }

    }

  }

}

I don't know if this worths a new release.
Sorry for the noise.

drikc’s picture

Nicorac push his patch of comment #15 into the git repository so it is available in the latest dev release. Thx!

drikc’s picture

Status: Needs review » Fixed

Pushed in 7.x.1.2 release

gaards’s picture

Would it be possible to add this code to the Drupal 6 version of Anonymous Posting as well? It would be much appreciated.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.