You are here

class commons_follow_handler_field_ops in Drupal Commons 7.3

Views field handler for the Flag operations links (flag/unflag).

Hierarchy

Expanded class hierarchy of commons_follow_handler_field_ops

1 string reference to 'commons_follow_handler_field_ops'
commons_follow_views_data_alter in modules/commons/commons_follow/commons_follow.module
Implements hook_views_data_alter().

File

modules/commons/commons_follow/includes/views/handlers/commons_follow_handler_field_ops.inc, line 13
Contains the flag Ops field handler.

View source
class commons_follow_handler_field_ops extends flag_handler_field_ops {
  function render($values) {
    global $user;

    // If the passed in user doesn't match the current user.
    if (isset($this->view->args[0]) && $user->uid != $this->view->args[0]) {
      if (!($flag = $this
        ->get_flag())) {

        // get_flag() itself will print a more detailed message.
        return t('Missing flag');
      }
      $entity_id = $values->{$this->aliases['entity_id']};
      $is_flagged = $values->{$this->aliases['is_flagged']};
      if (empty($this->flag_applies[$entity_id])) {

        // Flag does not apply to this entity.
        return;
      }
      if (!empty($this->options['link_type'])) {
        $flag->link_type = $this->options['link_type'];
      }
      $variables = array();
      $action = $is_flagged ? 'unflag' : 'flag';
      $variables['flag_css_name'] = str_replace('_', '-', $flag->name);
      $flag_wrapper_classes_array = array();
      $flag_wrapper_classes_array[] = 'flag-wrapper';
      $flag_wrapper_classes_array[] = 'flag-' . $variables['flag_css_name'];
      $flag_wrapper_classes_array[] = 'flag-' . $variables['flag_css_name'] . '-' . $entity_id;
      $variables['flag_wrapper_classes'] = implode(' ', $flag_wrapper_classes_array);
      $flag_classes_array = array();
      $flag_classes_array[] = 'flag';
      $flag_classes_array[] = $action . '-action';
      $flag_classes_array[] = 'flag-link-' . $flag->link_type;
      $variables['flag_classes'] = implode(' ', $flag_classes_array);
      $variables['is_flagged'] = $action;
      $variables['link_text'] = $flag
        ->get_label($action . '_short', $entity_id);
      return theme('commons_follow_otheruser_flag', $variables);
    }
    else {
      return parent::render($values);
    }

    //    return $flag->theme($is_flagged ? 'unflag' : 'flag', $entity_id);
  }

}

Members