You are here

public function OrderController::log in Ubercart 8.4

Displays a log of changes made to an order.

Parameters

\Drupal\uc_order\OrderInterface $uc_order: The order entity.

Return value

array A render array.

1 string reference to 'OrderController::log'
uc_order.routing.yml in uc_order/uc_order.routing.yml
uc_order/uc_order.routing.yml

File

uc_order/src/Controller/OrderController.php, line 76

Class

OrderController
Controller routines for order routes.

Namespace

Drupal\uc_order\Controller

Code

public function log(OrderInterface $uc_order) {
  $result = \Drupal::database()
    ->query('SELECT order_log_id, uid, changes, created FROM {uc_order_log} WHERE order_id = :id ORDER BY order_log_id DESC', [
    ':id' => $uc_order
      ->id(),
  ]);
  $header = [
    $this
      ->t('Time'),
    $this
      ->t('User'),
    $this
      ->t('Changes'),
  ];
  $rows = [];
  foreach ($result as $change) {
    $rows[] = [
      \Drupal::service('date.formatter')
        ->format($change->created, 'short'),
      [
        'data' => [
          '#theme' => 'username',
          '#account' => User::load($change->uid),
        ],
      ],
      [
        'data' => [
          '#markup' => $change->changes,
        ],
      ],
    ];
  }
  $build['log'] = [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No changes have been logged for this order.'),
  ];
  return $build;
}