You are here

public function AdminComments::view in Ubercart 8.4

Returns the contents of an order pane as a store administrator.

Parameters

\Drupal\uc_order\OrderInterface $order: The order that is being viewed.

string $view_mode: The view mode that is being used to render the order.

Return value

array A render array showing order data.

Overrides OrderPanePluginInterface::view

File

uc_order/src/Plugin/Ubercart/OrderPane/AdminComments.php, line 24

Class

AdminComments
View the admin comments, used for administrative notes and instructions.

Namespace

Drupal\uc_order\Plugin\Ubercart\OrderPane

Code

public function view(OrderInterface $order, $view_mode) {
  if ($view_mode != 'customer') {
    $build = [
      '#theme' => 'table',
      '#header' => [
        [
          'data' => $this
            ->t('Date'),
          'class' => [
            'date',
          ],
        ],
        [
          'data' => $this
            ->t('User'),
          'class' => [
            'user',
          ],
        ],
        [
          'data' => $this
            ->t('Comment'),
          'class' => [
            'message',
          ],
        ],
      ],
      '#rows' => [],
      '#attributes' => [
        'class' => [
          'order-pane-table uc-order-comments',
        ],
      ],
      '#empty' => $this
        ->t('This order has no admin comments associated with it.'),
    ];
    $comments = uc_order_comments_load($order
      ->id(), TRUE);
    foreach ($comments as $comment) {
      $build['#rows'][] = [
        [
          'data' => \Drupal::service('date.formatter')
            ->format($comment->created, 'short'),
          'class' => [
            'date',
          ],
        ],
        [
          'data' => [
            '#theme' => 'username',
            '#account' => User::load($comment->uid),
          ],
          'class' => [
            'user',
          ],
        ],
        [
          'data' => [
            '#markup' => $comment->message,
          ],
          'class' => [
            'message',
          ],
        ],
      ];
    }
    return $build;
  }
}