You are here

public function PartyController::invoke in Party 7

Same name and namespace in other branches
  1. 8.2 includes/party.entity.inc \PartyController::invoke()

Overrides EntityAPIController::invoke().

Add in our additional logic for party labels. This is in here rather than PartyController::save() so that we can get the label set as early as possible. The tricky case is when a plugin requires the party to be saved or we fall back to pid which also requires the party to be saved. For those cases, we need to update the label immediately after we write the record but before we invoke modules' implementation of hook_entity_insert(). However, in the more common use case, we ideally want the label to be set before hook_entity_presave() is invoked.

Overrides EntityAPIController::invoke

1 call to PartyController::invoke()
PartyController::setPrimaryFields in includes/party.entity.inc
Set the primary fields for the party.

File

includes/party.entity.inc, line 43
Contains the controller classes for Party entities.

Class

PartyController
The API controller class for the Party entity.

Code

public function invoke($hook, $party) {

  // In presave, trigger our label and primary fields update without a save.
  if ($hook == 'presave' && empty($party->primary_fields_updated)) {
    $this
      ->setPrimaryFields($party, FALSE);
  }
  elseif (in_array($hook, array(
    'insert',
    'update',
  )) && !empty($party->primary_fields_updated)) {
    unset($party->primary_fields_updated);
  }

  // In insert our primary fields ran before there was a pid, so we re-run
  // them in case we were dependant on a pid.
  if ($hook == 'insert') {

    // Set the party_attaching_party flag on any attached entities.
    foreach ($party->data_set_controllers as $controller) {
      foreach ($controller
        ->getEntities() as $entity) {
        $entity->party_attaching_party = $party->pid;
      }
    }

    // Set primary fields, storing any properties but deferring other stores.
    $needs_store = $this
      ->setPrimaryFields($party, FALSE);
    if ($needs_store & PartyController::UPDATE_PROPERTY) {
      drupal_write_record($this->entityInfo['base table'], $party, $this->idKey);
    }
  }

  // Trigger the rest of the invoke action.
  parent::invoke($hook, $party);
  if ($hook == 'insert' && $needs_store & PartyController::UPDATE_OTHER) {
    unset($party->is_new);
    $party
      ->save();
  }
}