You are here

public function GenericTransactor::executeTransaction in Transaction 8

Executes a transaction.

By calling this method, the transactor will set the result code in the transaction.

Parameters

\Drupal\transaction\TransactionInterface $transaction: The transaction to execute.

\Drupal\transaction\TransactionInterface $last_executed: The last executed transaction with the same type and target. Empty if this is the first one.

Return value

bool TRUE if transaction was executed, FALSE otherwise.

Overrides TransactorBase::executeTransaction

See also

\Drupal\transaction\TransactionInterface::getResultCode()

1 call to GenericTransactor::executeTransaction()
BalanceTransactor::executeTransaction in src/Plugin/Transaction/BalanceTransactor.php
Executes a transaction.
1 method overrides GenericTransactor::executeTransaction()
BalanceTransactor::executeTransaction in src/Plugin/Transaction/BalanceTransactor.php
Executes a transaction.

File

src/Plugin/Transaction/GenericTransactor.php, line 40

Class

GenericTransactor
Provides a generic transactor.

Namespace

Drupal\transaction\Plugin\Transaction

Code

public function executeTransaction(TransactionInterface $transaction, TransactionInterface $last_executed = NULL) {
  if (!parent::executeTransaction($transaction)) {
    return FALSE;
  }

  // Update the last execute transaction reference in the target entity.
  $settings = $transaction
    ->getType()
    ->getPluginSettings();
  if (isset($settings['last_transaction']) && ($target_entity = $transaction
    ->getTargetEntity()) && $target_entity
    ->hasField($settings['last_transaction'])) {
    $target_entity
      ->get($settings['last_transaction'])
      ->setValue($transaction);

    // Set the property indicating that the target entity was updated on
    // execution.
    $transaction
      ->setProperty(TransactionInterface::PROPERTY_TARGET_ENTITY_UPDATED, TRUE);
  }
  return TRUE;
}