public function ButtonController::save in Command Buttons 7
Overridden to care exportables that are overridden.
Overrides EntityAPIControllerExportable::save
File
- includes/
ButtonController.class.php, line 44 - Contains the controller class for the OA Button entity.
Class
- ButtonController
- Entity controller class.
Code
public function save($entity, DatabaseTransaction $transaction = NULL) {
$entity = (object) $entity;
// Determine if we will be inserting a new entity.
$entity->is_new = !(isset($entity->bid) && is_numeric($entity->bid));
$transaction = db_transaction();
// Set the timestamp fields.
if (empty($entity->created)) {
$entity->created = REQUEST_TIME;
}
$entity->changed = REQUEST_TIME;
field_attach_presave('command_button', $entity);
module_invoke_all('entity_presave', $entity, 'command_button');
try {
if (!$entity->is_new) {
drupal_write_record('command_buttons', $entity, 'bid');
field_attach_update('command_button', $entity);
module_invoke_all('entity_update', $entity, 'command_button');
}
else {
drupal_write_record('command_buttons', $entity);
field_attach_insert('command_button', $entity);
module_invoke_all('entity_insert', $entity, 'command_button');
}
return $entity;
} catch (Exception $e) {
$transaction
->rollback();
watchdog_exception('command_button', $e);
}
return FALSE;
}