You are here

function ctools_context_create_user_edit_form in Chaos Tool Suite (ctools) 7

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_edit_form'
user_edit_form.inc in plugins/contexts/user_edit_form.inc
Plugin to provide a user_edit_form context.

File

plugins/contexts/user_edit_form.inc, line 32
Plugin to provide a user_edit_form context.

Code

function ctools_context_create_user_edit_form($empty, $user = NULL, $conf = FALSE) {

  // Determine the user category.
  $category = !empty($conf['category']) ? $conf['category'] : FALSE;
  unset($conf['category']);

  // If no category was specified, use the default 'account'.
  if (!$category) {
    $category = 'account';
  }

  // Return previously created contexts, per category.
  static $created = array();
  if (!empty($created[$category])) {
    return $created[$category];
  }
  $context = new ctools_context(array(
    'form',
    'user_edit',
    'user_form',
    'user_edit_form',
    'user',
    'entity:user',
  ));

  // Store this context for later.
  $created[$category] = $context;
  $context->plugin = 'user_edit_form';
  if ($empty) {
    return $context;
  }
  if (!empty($conf)) {

    // In this case, $user is actually our $conf array.
    $uid = is_array($user) && isset($user['uid']) ? $user['uid'] : (is_object($user) ? $user->uid : 0);
    if (module_exists('translation')) {
      if ($translation = module_invoke('translation', 'user_uid', $uid, $GLOBALS['language']->language)) {
        $uid = $translation;
        $reload = TRUE;
      }
    }
    if (is_array($user) || !empty($reload)) {
      $user = user_load($uid);
    }
  }
  if (!empty($user)) {
    $form_id = 'user_profile_form';
    $form_state = array(
      'want form' => TRUE,
      'build_info' => array(
        'args' => array(
          $user,
          $category,
        ),
      ),
    );
    $file = drupal_get_path('module', 'user') . '/user.pages.inc';
    require_once DRUPAL_ROOT . '/' . $file;

    // This piece of information can let other modules know that more files
    // need to be included if this form is loaded from cache:
    $form_state['build_info']['files'] = array(
      $file,
    );
    $form = drupal_build_form($form_id, $form_state);

    // Fill in the 'node' portion of the context.
    $context->data = $user;
    $context->title = isset($user->name) ? $user->name : '';
    $context->argument = $user->uid;
    $context->form = $form;
    $context->form_state =& $form_state;
    $context->form_id = $form_id;
    $context->form_title = isset($user->name) ? $user->name : '';
    $context->restrictions['form'] = array(
      'form',
    );
    return $context;
  }
}