• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

modules/user/views_handler_field_user_name.inc

00001 <?php
00007 class views_handler_field_user_name extends views_handler_field_user {
00011   function init(&$view, &$data) {
00012     parent::init($view, $data);
00013     if (!empty($this->options['overwrite_anonymous']) || !empty($this->options['format_username'])) {
00014       $this->additional_fields['uid'] = 'uid';
00015     }
00016   }
00017 
00018   function option_definition() {
00019     $options = parent::option_definition();
00020 
00021     $options['overwrite_anonymous'] = array('default' => FALSE);
00022     $options['anonymous_text'] = array('default' => '', 'translatable' => TRUE);
00023     $options['format_username'] = array('default' => TRUE);
00024 
00025     return $options;
00026   }
00027 
00028   function options_form(&$form, &$form_state) {
00029     $form['format_username'] = array(
00030       '#title' => t('Use formatted username'),
00031       '#type' => 'checkbox',
00032       '#default_value' => !empty($this->options['format_username']),
00033       '#description' => t('If checked, the username will be formatted by the system. If unchecked, it will be displayed raw.'),
00034       '#fieldset' => 'more',
00035     );
00036     $form['overwrite_anonymous'] = array(
00037       '#title' => t('Overwrite the value to display for anonymous users'),
00038       '#type' => 'checkbox',
00039       '#default_value' => !empty($this->options['overwrite_anonymous']),
00040       '#description' => t('Enable to display different text for anonymous users.'),
00041       '#fieldset' => 'more',
00042     );
00043     $form['anonymous_text'] = array(
00044       '#title' => t('Text to display for anonymous users'),
00045       '#type' => 'textfield',
00046       '#default_value' => $this->options['anonymous_text'],
00047       '#dependency' => array(
00048         'edit-options-overwrite-anonymous' => array(1),
00049       ),
00050       '#fieldset' => 'more',
00051     );
00052 
00053     parent::options_form($form, $form_state);
00054   }
00055 
00056   function render_link($data, $values) {
00057     $account = new stdClass();
00058     $account->uid = $this->get_value($values, 'uid');
00059     $account->name = $this->get_value($values);
00060     if (!empty($this->options['link_to_user']) || !empty($this->options['overwrite_anonymous'])) {
00061       if (!empty($this->options['overwrite_anonymous']) && !$account->uid) {
00062         // This is an anonymous user, and we're overriting the text.
00063         return check_plain($this->options['anonymous_text']);
00064       }
00065       elseif (!empty($this->options['link_to_user'])) {
00066         $account->name = $this->get_value($values);
00067         return theme('username', array('account' => $account));
00068       }
00069     }
00070     // If we want a formatted username, do that.
00071     if (!empty($this->options['format_username'])) {
00072       return format_username($account);
00073     }
00074     // Otherwise, there's no special handling, so return the data directly.
00075     return $data;
00076   }
00077 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1