You are here

public function EntityAPIController::invoke in Entity API 7

Implements EntityAPIControllerInterface.

Overrides EntityAPIControllerInterface::invoke

3 calls to EntityAPIController::invoke()
EntityAPIController::delete in includes/entity.controller.inc
Implements EntityAPIControllerInterface.
EntityAPIController::deleteRevision in includes/entity.controller.inc
Implements EntityAPIControllerRevisionableInterface::deleteRevision().
EntityAPIController::save in includes/entity.controller.inc
Implements EntityAPIControllerInterface.
1 method overrides EntityAPIController::invoke()
EntityAPIControllerExportable::invoke in includes/entity.controller.inc
Overridden to care about reverted bundle entities and to skip Rules.

File

includes/entity.controller.inc, line 335
Provides a controller building upon the core controller but providing more features like full CRUD functionality.

Class

EntityAPIController
A controller implementing EntityAPIControllerInterface for the database.

Code

public function invoke($hook, $entity) {

  // entity_revision_delete() invokes hook_entity_revision_delete() and
  // hook_field_attach_delete_revision() just as node module does. So we need
  // to adjust the name of our revision deletion field attach hook in order to
  // stick to this pattern.
  $field_attach_hook = $hook == 'revision_delete' ? 'delete_revision' : $hook;
  if (!empty($this->entityInfo['fieldable']) && function_exists($function = 'field_attach_' . $field_attach_hook)) {
    $function($this->entityType, $entity);
  }
  if (!empty($this->entityInfo['bundle of']) && entity_type_is_fieldable($this->entityInfo['bundle of'])) {
    $type = $this->entityInfo['bundle of'];

    // Call field API bundle attachers for the entity we are a bundle of.
    if ($hook == 'insert') {
      field_attach_create_bundle($type, $entity->{$this->bundleKey});
    }
    elseif ($hook == 'delete') {
      field_attach_delete_bundle($type, $entity->{$this->bundleKey});
    }
    elseif ($hook == 'update' && $entity->original->{$this->bundleKey} != $entity->{$this->bundleKey}) {
      field_attach_rename_bundle($type, $entity->original->{$this->bundleKey}, $entity->{$this->bundleKey});
    }
  }

  // Invoke the hook.
  module_invoke_all($this->entityType . '_' . $hook, $entity);

  // Invoke the respective entity level hook.
  if ($hook == 'presave' || $hook == 'insert' || $hook == 'update' || $hook == 'delete') {
    module_invoke_all('entity_' . $hook, $entity, $this->entityType);
  }

  // Invoke rules.
  if (module_exists('rules')) {
    rules_invoke_event($this->entityType . '_' . $hook, $entity);
  }
}