Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I want to extend the user profile with a rank (a decimal ranging from 500 - 2500), which needs to be updated on a regular basis (10 times per minute) for several users. (it is for http://achtungdiekurve.net/ ) I already implemented it with a seperate table, containing a rank field and implemented a table to show the rankings (http://achtungdiekurve.net/ranks ).

However, I want to use views to create this table. But I cant seem to alter the entity type user in such a way, that it shows Rank in the views forms. How to do this? My current code:

<?php
function achtung_entity_property_info_alter(&$info) {

  $info["user"]["properties"]["rank"] = array(
    "label" => t("Rank"),
    "description" => t("The rank of the user"),
    "type" => "decimal",
    "getter callback" => "achtung_get_entity_callback",
    "computed" => true,
    "entity views field" => true,
    "query callback" => "entity_property_query",
  );
  watchdog("ACHTUNG entity info alter", "<pre>".print_r($info, true)."</pre>");
  return $info;

}
function achtung_get_entity_callback($account, $options, $name, $entity_type) {
  watchdog("ACHTUNG entity info callback", "<pre>".print_r($account, true)."</pre>");
  return 2;
}
?>
share|improve this question
add comment

2 Answers

Although I haven't had a chance to play with it myself just yet, assuming everything else is implemented correctly, it seems as though using EntityFieldQuery Views Backend as your Views backend should make your new Rank field visible to Views.

share|improve this answer
add comment

AFAIK, the default Views backend does not support Entity properties. Instead, it support fields from the Field API and known entity properties such as nid. In order to use your custom property as a Views field, you need to either use EntityFieldQuery Views Backend (as suggested by David Watson) or provide an implementation of hook_views_data() to expose your table and column to Views.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.