You are here

function realistic_dummy_content_api_user_presave in Realistic Dummy Content 7

Implements hook_user_presave().

File

api/realistic_dummy_content_api.module, line 89
API code allowing other modules to generate realistic dummy content. See the Realistic Dummy Content module for an example of how to use.

Code

function realistic_dummy_content_api_user_presave(&$edit, $account, $category) {

  // This hook is called when content is updated, in which case we don't want
  // to tamper with it. When content is first created, the $account's is_new
  // property is set to FALSE, se we can't depend on that to determine whether
  // the user is new or not. However, $edit['picture_delete'] is _only_ set when
  // users are updated, so we can check for that to determine whether or not to
  // continue modifying the account.
  if (isset($edit['picture_delete'])) {

    // not a new account, don't mess with it.
    return;
  }

  // At this point we know we are dealing with a new user.
  // $edit['uid'] can have several values:
  // This hook is invoked twice when content is created via devel_generate,
  // once with $edit['uid'] set to NULL (which causes us to do nothing) and
  // once with $edit['uid'] set to the UID of newly-created user object.
  // When the user is changed via the admin interface, this hook is invoked
  // but $edit['uid'] is not set. $edit['uid'] is never set during testing,
  // so we use $account->uid instead. $account->uid is set whether we are
  // creating the user in our test code or it's created via devel_generate.
  if (isset($account->uid) && $account->uid) {
    $filter = array(
      'include' => array(
        'picture',
      ),
    );
    $user = (object) $edit;
    _realistic_dummy_content_api_entity_presave($user, 'user', $filter);
    $edit = (array) $user;
  }
}