public function Profile::save in Profile 2 7
Same name and namespace in other branches
- 7.2 profile2.module \Profile::save()
Permanently saves the entity.
Overrides Entity::save
See also
File
- ./
profile2.module, line 1000 - Support for configurable user profiles.
Class
- Profile
- The class used for profile entities.
Code
public function save() {
// Don't create a new profile if the user already has one of the same type.
$existing_profile = profile2_load_by_user($this->uid, $this->type);
if (empty($this->pid) && !empty($existing_profile)) {
watchdog('profile2_create', '@type profile already exists for user @uid', array(
'@uid' => $this->uid,
'@type' => $this->type,
), WATCHDOG_WARNING);
return;
}
// Care about setting created and changed values. But do not automatically
// set a created values for already existing profiles.
if (empty($this->created) && (!empty($this->is_new) || !$this->pid)) {
$this->created = REQUEST_TIME;
}
$this->changed = REQUEST_TIME;
// Clear the static cache from profile2_load_by_user() before saving, so
// that profiles are correctly loaded in insert/update hooks.
$cache =& drupal_static('profile2_load_by_user', array());
unset($cache[$this->uid]);
return parent::save();
}