18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6<br />

// Save the initial revision.<br />

$this->saveRevision($artwork, $user->uid);<br />

$op = 'insert';<br />

}<br />

else {<br />

// Save the updated artwork.<br />

drupal_write_record('artwork', $artwork, 'aid');<br />

if (!empty($artwork->revision)) {<br />

$this->saveRevision($artwork, $user->uid);<br />

}<br />

else {<br />

$this->saveRevision($artwork, $user->uid, TRUE);<br />

$update_artwork = FALSE;<br />

}<br />

}<br />

$op = 'update';<br />

// If the revision ID is new or updated, save it to the artwork.<br />

if ($update_artwork) {<br />

db_update('artwork')<br />

->fields(array('vid' => $artwork->vid))<br />

->condition('aid', $artwork->aid)<br />

->execute();<br />

}<br />

// Save fields.<br />

$function = 'field_attach_' . $op;<br />

$function('artwork', $artwork);<br />

module_invoke_all('entity_' . $op, $artwork, 'artwork');<br />

// Clear internal properties.<br />

unset($artwork->is_new);<br />

// Ignore slave server temporarily to give time for the saved<br />

// order to be propagated to the slave.<br />

db_ignore_slave();<br />

return $artwork;<br />

}<br />

[ 173 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!