You are here

function cer_processing_entity in Corresponding Entity References 7.3

Same name and namespace in other branches
  1. 7 cer.module \cer_processing_entity()
  2. 7.2 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 object (optionally wrapped), or its ID.

string $entity_type: The entity type. If $entity is wrapped, this can be NULL since the entity type is known by the wrapper.

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.

4 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().
cer_node_insert in ./cer.module
Implements hook_node_insert().
1 string reference to 'cer_processing_entity'
cer_bulk_update_form_submit in ./cer.admin.inc
The update form. Allows bulk updating of current entities.

File

./cer.module, line 184

Code

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

  // Don't do anything if the MAINTENANCE_MODE flag is set. This isn't the same thing
  // as user-facing maintenance mode, but rather is set when running, say, update.php
  // or another relatively low-level operation. This was added to prevent CER from
  // running while updating from 1.x or 2.x, since classes may not yet be registered
  // yet and we don't want to cause fatal errors during update.
  if (defined('MAINTENANCE_MODE')) {
    return;
  }

  // Don't process anything that hasn't got the cer data structure: this provides an
  // opportunity for other modules to opt their entities out of CER processing.
  if ($entity instanceof EntityStructureWrapper) {
    try {

      // If there is no such a property an exception will be thrown.
      $entity
        ->getPropertyInfo('cer');
    } catch (EntityMetadataWrapperException $e) {
      return;
    }
  }
  if ($entity instanceof EntityDrupalWrapper) {

    // Under certain circumstances, the cer struct may not be known to Entity
    // API. So check for that before doing any actual processing. If it's not
    // known yet, rebuild the property info cache and re-instantiate the
    // wrapper with all the latest property definitions.
    try {
      $entity
        ->getPropertyInfo('cer');
    } catch (EntityMetadataWrapperException $e) {
      entity_property_info_cache_clear();
      $entity = new EntityDrupalWrapper($entity
        ->type(), $entity
        ->value());
    }
    $finder = new CerPresetFinder($entity);
    foreach ($finder
      ->execute() as $preset) {
      $handler = new CerPresetHandler($preset, $entity);
      $handler
        ->{$op}();
    }
    if ($context) {
      if (!isset($context['results']['count'])) {
        $context['results']['count'] = 0;
      }
      $context['results']['count']++;
    }
  }
  elseif ($entity_type) {
    if (is_numeric($entity)) {
      $entity = entity_object_load($entity, $entity_type);
    }
    if (is_object($entity) && empty($entity->cer_processed)) {
      cer_processing_entity($op, new EntityDrupalWrapper($entity_type, $entity), NULL, $context);
    }
  }
}