cvs diff: Diffing modules/user
Index: modules/user/views_handler_field_user_name.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/modules/user/views_handler_field_user_name.inc,v
retrieving revision 1.1
diff -u -p -r1.1 views_handler_field_user_name.inc
--- modules/user/views_handler_field_user_name.inc	3 Sep 2008 19:21:30 -0000	1.1
+++ modules/user/views_handler_field_user_name.inc	3 Feb 2009 01:52:07 -0000
@@ -4,16 +4,59 @@
  * Field handler to provide simple renderer that allows using a themed user link
  */
 class views_handler_field_user_name extends views_handler_field_user {
+  /**
+   * Add uid in the query so we can test for anonymous if needed.
+   */
+  function init(&$view, &$data) {
+    parent::init($view, $data);
+    if (!empty($this->options['overwrite_anonymous'])) {
+      $this->additional_fields['uid'] = 'uid';
+    }
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['overwrite_anonymous'] = array('default' => FALSE);
+    $options['anonymous_text'] = array('default' => '');
+
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+
+    $form['overwrite_anonymous'] = array(
+      '#title' => t('Overwrite the value to display for anonymous users'),
+      '#type' => 'checkbox',
+      '#default_value' => !empty($this->options['overwrite_anonymous']),
+      '#description' => t('If selected, you will see a field to enter the text to use for anonymous users.'),
+    );
+    $form['anonymous_text'] = array(
+      '#title' => t('Text to display for anonymous users'),
+      '#type' => 'textfield',
+      '#default_value' => $this->options['anonymous_text'],
+      '#dependency' => array(
+        'checkbox:options[overwrite_anonymous]' => array('default'),
+      ),
+    );
+  }
+
   function render_link($data, $values) {
-    if (!empty($this->options['link_to_user'])) {
+    if (!empty($this->options['link_to_user']) || !empty($this->options['overwrite_anonymous'])) {
       $account = new stdClass();
-      $account->name = $values->{$this->field_alias};
       $account->uid = $values->{$this->aliases['uid']};
-      return theme('username', $account);
-    }
-    else {
-      return $data;
+      if (!empty($this->options['overwrite_anonymous']) && !$account->uid) {
+        // This is an anonymous user, and we're overriting the text.
+        return check_plain($this->options['anonymous_text']);
+      }
+      elseif (!empty($this->options['link_to_user'])) {
+        $account->name = $values->{$this->field_alias};
+        return theme('username', $account);
+      }
     }
+    // Otherwise, there's no special handling, so return the data directly.
+    return check_plain($data);
   }
 }
 
