public function Drupal7::hookUserPresave in Realistic Dummy Content 7.2
Same name and namespace in other branches
- 8.2 api/src/Framework/Drupal7.php \Drupal\realistic_dummy_content_api\Framework\Drupal7::hookUserPresave()
File
- api/
src/ Framework/ Drupal7.php, line 86
Class
- Drupal7
- Drupal 7-specific code.
Namespace
Drupal\realistic_dummy_content_api\FrameworkCode
public function hookUserPresave(&$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;
$this
->genericEntityPresave($user, 'user', $filter);
$edit = (array) $user;
}
}