You are here

public function CerPresetHandler::insert in Corresponding Entity References 7.3

Process an entity insert. This loops through the referenced entity $IDs and adds a reference to this entity if the reference doesn't already have one.

1 call to CerPresetHandler::insert()
CerPresetHandler::update in includes/CerPresetHandler.inc
Process an entity update. This could be either a normal update done by a user, or a bulk update.

File

includes/CerPresetHandler.inc, line 49
Contains CerPresetHandler.

Class

CerPresetHandler
@class Contains the logic for performing CER operations on a single entity, using a single preset.

Code

public function insert(array $IDs = array()) {

  // If no IDs were passed in, use the current reference set.
  $IDs = $IDs ? $IDs : $this->refIDs;

  // Get this entity's ID right now, so we don't have to keep calling
  // $this->entity->cer->owner->getIdentifier(). Hooray for micro-optimization!
  $myID = $this->entity->cer->owner
    ->getIdentifier();
  foreach ($this
    ->load($IDs) as $ref) {
    $handler = $this->right
      ->getHandler($ref);

    // Only create the backreference if the reference doesn't already reference
    // this entity (which it might, if there is more than one preset that references
    // a single field instance).
    if (!in_array($myID, $handler
      ->getIDs())) {
      $handler
        ->add($this->entity->cer->owner);
    }
  }
}