You are here

function entity_metadata_user_get_properties in Entity API 7

Callback for getting user properties.

See also

entity_metadata_user_entity_info_alter()

1 string reference to 'entity_metadata_user_get_properties'
entity_metadata_user_entity_property_info in modules/user.info.inc
Implements hook_entity_property_info() on top of user module.

File

modules/callbacks.inc, line 364
Provides various callbacks for the whole core module integration.

Code

function entity_metadata_user_get_properties($account, array $options, $name, $entity_type) {
  switch ($name) {
    case 'last_access':

      // In case there was no access the value is 0, but we have to return NULL.
      return empty($account->access) ? NULL : $account->access;
    case 'last_login':
      return empty($account->login) ? NULL : $account->login;
    case 'name':
      return empty($account->uid) ? variable_get('anonymous', t('Anonymous')) : $account->name;
    case 'url':
      if (empty($account->uid)) {
        return NULL;
      }
      $return = entity_uri('user', $account);
      return $return ? url($return['path'], $return['options'] + $options) : '';
    case 'edit_url':
      return empty($account->uid) ? NULL : url("user/{$account->uid}/edit", $options);
    case 'roles':
      return isset($account->roles) ? array_keys($account->roles) : array();
    case 'theme':
      return empty($account->theme) ? variable_get('theme_default', 'bartik') : $account->theme;
  }
}