You are here

function cer_processing_entity in Corresponding Entity References 7.2

Same name and namespace in other branches
  1. 7.3 cer.module \cer_processing_entity()
  2. 7 cer.module \cer_processing_entity()

Process a entity's corresponding entity references.

Parameters

string $op : The operation being performed on the entity (insert, update, or delete).

object $entity: The entity or the entity's id.

string $entity_type: The entity type.

array $context: Either the Batch API context (since this is the callback function used during bulk update) or NULL if we're not in a batch job.

3 calls to cer_processing_entity()
cer_entity_delete in ./cer.module
Implements hook_entity_delete().
cer_entity_insert in ./cer.module
Implements hook_entity_insert().
cer_entity_update in ./cer.module
Implements hook_entity_update().
1 string reference to 'cer_processing_entity'
cer_update_form_submit in ./cer.admin.inc
The update form. Allows updating of current entitys.

File

./cer.module, line 203
Main module file.

Code

function cer_processing_entity($op, $entity, $entity_type, &$context = NULL) {

  // Load the entity if we're given an ID rather than an entity.
  if (!is_object($entity)) {
    $entity = entity_load($entity_type, array(
      $entity,
    ));
    $entity = reset($entity);
  }

  // If the entity is of the wrong type, entity_extract_IDs() will throw
  // EntityMalformedException and rightfully bail out here.
  list(, , $bundle) = entity_extract_IDs($entity_type, $entity);
  $result = cer_preset_load_enabled();
  foreach ($result as $row) {
    $keys = explode('*', $row->entity_types_content_fields);
    if ($keys[0] == $entity_type && $keys[1] == $bundle) {
      try {
        $handler = new CerHandler($row->entity_types_content_fields, $entity);
        call_user_func(array(
          $handler,
          $op,
        ));
      } catch (CerException $e) {
        if (isset($context)) {
          $context['results']['errors'][] = $e;
        }
        else {
          throw $e;
        }
      }
    }
    if ($keys[3] == $entity_type && $keys[4] == $bundle) {
      $preset = implode('*', array(
        $keys[3],
        $keys[4],
        $keys[5],
        $keys[0],
        $keys[1],
        $keys[2],
      ));
      try {
        $handler = new CerHandler($preset, $entity);
        call_user_func(array(
          $handler,
          $op,
        ));
      } catch (CerException $e) {
        if (isset($context)) {
          $context['results']['errors'][] = $e;
        }
        else {
          throw $e;
        }
      }
    }
  }
  if (isset($context)) {
    $context['results']['count']++;
  }
}