You are here

class EntityBlockController in Entity Blocks 7

The controller class for Entity Block.

Hierarchy

Expanded class hierarchy of EntityBlockController

1 string reference to 'EntityBlockController'
entity_block_entity_info in ./entity_block.module
Implements hook_entity_info().

File

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

View source
class EntityBlockController extends DrupalDefaultEntityController implements EntityBlockControllerInterface {

  /**
   * Create and return a new entity_block entity.
   */
  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;
  }

  /**
   * Saves the entity.
   */
  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;
  }

  /**
   * Deletes an entity_block.
   */
  public function delete($entity) {
    $this
      ->deleteMultiple(array(
      $entity,
    ));
  }

  /**
   * Deletes multiple entity_blocks.
   *
   * @param array $entities
   *   An array of entity IDs or a single numeric ID.
   * @throws \Exception
   */
  public function deleteMultiple($entities) {
    $entity_block_ids = array();
    if (!empty($entities)) {
      $transaction = db_transaction();
      try {
        foreach ($entities as $entity) {

          // Invoke hook_entity_delete().
          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;
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalDefaultEntityController::$cache protected property Whether this entity type should use the static cache.
DrupalDefaultEntityController::$entityCache protected property Static cache of entities, keyed by entity ID.
DrupalDefaultEntityController::$entityInfo protected property Array of information about the entity.
DrupalDefaultEntityController::$entityType protected property Entity type for this controller instance.
DrupalDefaultEntityController::$hookLoadArguments protected property Additional arguments to pass to hook_TYPE_load().
DrupalDefaultEntityController::$idKey protected property Name of the entity's ID field in the entity database table.
DrupalDefaultEntityController::$revisionKey protected property Name of entity's revision database table field, if it supports revisions.
DrupalDefaultEntityController::$revisionTable protected property The table that stores revisions, if the entity supports revisions.
DrupalDefaultEntityController::attachLoad protected function Attaches data to entities upon loading. 4
DrupalDefaultEntityController::buildQuery protected function Builds the query to load the entity. 4
DrupalDefaultEntityController::cacheGet protected function Gets entities from the static cache. 1
DrupalDefaultEntityController::cacheSet protected function Stores entities in the static entity cache.
DrupalDefaultEntityController::cleanIds protected function Ensures integer entity IDs are valid.
DrupalDefaultEntityController::filterId protected function Callback for array_filter that removes non-integer IDs.
DrupalDefaultEntityController::load public function Implements DrupalEntityControllerInterface::load(). Overrides DrupalEntityControllerInterface::load
DrupalDefaultEntityController::resetCache public function Implements DrupalEntityControllerInterface::resetCache(). Overrides DrupalEntityControllerInterface::resetCache
DrupalDefaultEntityController::__construct public function Constructor: sets basic variables.
EntityBlockController::create public function Create and return a new entity_block entity. Overrides EntityBlockControllerInterface::create
EntityBlockController::delete public function Deletes an entity_block. Overrides EntityBlockControllerInterface::delete
EntityBlockController::deleteMultiple public function Deletes multiple entity_blocks.
EntityBlockController::save public function Saves the entity. Overrides EntityBlockControllerInterface::save