You are here

function ctools_context_create_user in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 plugins/contexts/user.inc \ctools_context_create_user()

It's important to remember that $conf is optional here, because contexts are not always created from the UI.

1 string reference to 'ctools_context_create_user'
user.inc in plugins/contexts/user.inc
Plugin to provide a user context

File

plugins/contexts/user.inc, line 33
Plugin to provide a user context

Code

function ctools_context_create_user($empty, $data = NULL, $conf = FALSE) {
  $context = new ctools_context('user');
  $context->plugin = 'user';
  if ($empty) {
    return $context;
  }
  if ($conf) {
    if ($data['type'] == 'current') {
      global $user;
      $data = $user;
      if (user_is_logged_in()) {
        $data->logged_in_user = TRUE;
      }
    }
    else {
      $data = user_load(array(
        'uid' => $data['uid'],
      ));
    }
  }
  if (!empty($data)) {
    $context->data = $data;
    $context->title = isset($data->name) ? $data->name : t('Anonymous');
    $context->argument = $data->uid;
    return $context;
  }
}