entity_block.controller.inc in Entity Blocks 7
The controller for the EntityBlock entity.
File
entity_block.controller.inc
View source
<?php
interface EntityBlockControllerInterface extends DrupalEntityControllerInterface {
public function create();
public function save($entity);
public function delete($entity);
}
class EntityBlockController extends DrupalDefaultEntityController implements EntityBlockControllerInterface {
public function create() {
$entity = new stdClass();
$entity->type = 'entity_block';
$entity->bundle = 'entity_block';
$entity->title = '';
$entity->entity_block_id = 0;
$entity->target_entity_type = 'node';
$entity->target_bundle = '';
$entity->target_view_mode = '';
$entity->target_entity_id = '';
return $entity;
}
public function save($entity) {
module_invoke_all('entity_presave', $entity, 'entity_block');
$primary_keys = $entity->entity_block_id ? 'entity_block_id' : array();
drupal_write_record('entity_block', $entity, $primary_keys);
$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;
}
public function delete($entity) {
$this
->deleteMultiple(array(
$entity,
));
}
public function deleteMultiple($entities) {
$entity_block_ids = array();
if (!empty($entities)) {
$transaction = db_transaction();
try {
foreach ($entities as $entity) {
module_invoke_all('entity_delete', $entity, 'entity_block');
field_attach_delete('entity_block', $entity);
$entity_block_ids[] = $entity->entity_block_id;
}
db_delete('entity_block')
->condition('entity_block_id', $entity_block_ids, 'IN')
->execute();
} catch (Exception $e) {
$transaction
->rollback();
watchdog_exception('entity_block', $e);
throw $e;
}
}
}
}