You are here

function datalayer_get_user_data in dataLayer 7

Same name and namespace in other branches
  1. 8 datalayer.module \datalayer_get_user_data()

Return all user data based on configured URL patterns.

Return value

array The user data.

1 call to datalayer_get_user_data()
datalayer_preprocess_page in ./datalayer.module
Implements hook_preprocess_HOOK().

File

./datalayer.module, line 221
Client-side data space.

Code

function datalayer_get_user_data() {
  global $user;
  $user_data = array();
  if (!user_is_anonymous()) {
    $exp_user_urls = variable_get('datalayer_expose_user_details', array());
    $exp_user_roles = array_filter(variable_get('datalayer_expose_user_details_roles', array()));
    $matched_roles = !empty($exp_user_roles) ? array_intersect_key($user->roles, $exp_user_roles) : $user->roles;

    // Honor settings.
    if ($exp_user_urls && count($matched_roles)) {
      $path = current_path();
      $path_alias = drupal_lookup_path('alias', $path);
      if (drupal_match_path($path, $exp_user_urls) || drupal_match_path($path_alias, $exp_user_urls)) {

        // Output various entity properties. Allow additions/alterations.
        // NOTE: Properties mean different things on different entity types.
        $properties = _datalayer_collect_meta_properties('current_user');
        $user_meta = variable_get('datalayer_current_user_meta', array());
        $selected_properties = _datalayer_get_selected_properties($properties, $user_meta);
        $user_prefix = 'user';
        $user_data = _datalayer_collect_meta_values($selected_properties, $user, $user_prefix);
        if (in_array('roles', $selected_properties)) {
          $user_data[$user_prefix . 'Roles'] = array_values($matched_roles);
        }
      }
    }
  }
  return $user_data;
}