You are here

public function PartyController::invoke in Party 8.2

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

Implements EntityAPIControllerInterface.

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.

1 call to PartyController::invoke()
PartyController::setLabel in includes/party.entity.inc
Set the label on a Party object using the first label plugin (when ordered by weight) that returns a non-empty value.

File

includes/party.entity.inc, line 25
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') {
    $this
      ->setLabel($party, FALSE);
    $this
      ->setPrimaryFields($party, FALSE);
  }

  // In insert, if our label is empty, set our fallback and save.
  // @TODO: due to the use of the PID party label plugin as a stopper, we
  // we need to compare it to a stopper response from the plugin. Once we
  // rework the label plugins we can get rid of this uglyness and check
  // for an empty.
  if ($hook == 'insert' && $party->label == t('Party')) {
    $party->label = t('Party @pid', array(
      '@pid' => $party->pid,
    ));
    db_query('UPDATE {party} SET label = :label WHERE pid = :pid', array(
      ':label' => $party->label,
      ':pid' => $party->pid,
    ));
  }

  // Trigger the rest of the invoke action.
  parent::invoke($hook, $party);
}