You are here

public function EntityBlockController::save in Entity Blocks 7

Saves the entity.

Overrides EntityBlockControllerInterface::save

File

./entity_block.controller.inc, line 63
The controller for the EntityBlock entity.

Class

EntityBlockController
The controller class for Entity Block.

Code

public function save($entity) {

  // Invoke hook_entity_presave().
  module_invoke_all('entity_presave', $entity, 'entity_block');

  // Get the primary key.
  $primary_keys = $entity->entity_block_id ? 'entity_block_id' : array();

  // Save the entity.
  drupal_write_record('entity_block', $entity, $primary_keys);

  // Callback hooks.
  $invocation = 'entity_insert';
  if (empty($primary_keys)) {
    field_attach_insert('entity_block', $entity);
  }
  else {
    field_attach_update('entity_block', $entity);
    $invocation = 'entity_update';
  }
  module_invoke_all($invocation, $entity, 'entity_block');
  return $entity;
}