profile2 extends Entity class and should provide a return value when saving Objects:

Entity Module API - entity_save:

For entity types provided by the CRUD API, SAVED_NEW or SAVED_UPDATED is returned depending on the operation performed. If there is no information how to save the entity, FALSE is returned.

This can be easily provided by 'forwarding' the return value from super class Entity:

  public function save() {
    // 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;

    $success = parent::save();
    // Update the static cache from profile2_load_by_user().
    $cache = &drupal_static('profile2_load_by_user', array());
    if (isset($cache[$this->uid])) {
      $cache[$this->uid][$this->type] = $this->pid;
    }
    return $success;
  }

Comments

stelli created an issue. See original summary.

joachim’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
Status: Active » Needs work
Issue tags: -API Implementation Compliance Requirements

Looks good, but needs spaces either side of the =.

stelli’s picture

Issue summary: View changes
StatusFileSize
new526 bytes

Fixed missing spaces

joachim’s picture

Status: Needs work » Reviewed & tested by the community

Thanks!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: profile2_save_return_value.patch, failed testing.

stelli’s picture

StatusFileSize
new510 bytes

Patch converted to unix-style line endings.

stelli’s picture

StatusFileSize
new521 bytes

Fixed paths and filename, applicable by:

patch -p1 < profile2_save_return_value.patch

The last submitted patch, 3: profile2_save_return_value.patch, failed testing.

  • Spleshka committed 9a05fc7 on 7.x-1.x authored by stelli
    Issue #2623022 by stelli, joachim, Spleshka: No return value for save()...
spleshka’s picture

Status: Needs work » Fixed

Thanks for the patch & review guys. I've tested it myself and commited to 7.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.