You are here

public function Order::logChanges in Ubercart 8.4

Logs changes made to an order.

Parameters

array $changes: An array of changes. Two formats are allowed:

  • keys: Keys being the name of the field changed and the values being associative arrays with the keys 'old' and 'new' to represent the old and new values of the field. These will be converted into a changed message.
  • string: A pre-formatted string describing the change. This is useful for logging details like payments.

Return value

$this

Overrides OrderInterface::logChanges

1 call to Order::logChanges()
Order::postSave in uc_order/src/Entity/Order.php
Acts on a saved entity before the insert or update hook is invoked.

File

uc_order/src/Entity/Order.php, line 476

Class

Order
Defines the order entity class.

Namespace

Drupal\uc_order\Entity

Code

public function logChanges(array $changes) {
  if (!empty($changes)) {
    foreach ($changes as $key => $value) {
      if (is_array($value)) {
        $entry = t('@key changed from %old to %new.', [
          '@key' => $key,
          '%old' => $value['old'],
          '%new' => $value['new'],
        ]);
      }
      else {
        $entry = (string) $value;
      }
      $markup = [
        '#markup' => $entry,
      ];
      \Drupal::database()
        ->insert('uc_order_log')
        ->fields([
        'order_id' => $this
          ->id(),
        'uid' => \Drupal::currentUser()
          ->id(),
        'changes' => \Drupal::service('renderer')
          ->renderPlain($markup),
        'created' => REQUEST_TIME,
      ])
        ->execute();
    }
  }
  return $this;
}