You are here

public function AdminComments::buildForm in Ubercart 8.4

Form constructor.

Parameters

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

array $form: An array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides EditableOrderPanePluginInterface::buildForm

File

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

Class

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

Namespace

Drupal\uc_order\Plugin\Ubercart\OrderPane

Code

public function buildForm(OrderInterface $order, array $form, FormStateInterface $form_state) {
  $items = [];
  $comments = uc_order_comments_load($order
    ->id(), TRUE);
  foreach ($comments as $comment) {
    $items[] = [
      'username' => [
        '#theme' => 'username',
        '#account' => User::load($comment->uid),
        '#prefix' => '[',
        '#suffix' => '] ',
      ],
      'message' => [
        '#markup' => $comment->message,
      ],
    ];
  }
  $form['comments'] = [
    '#theme' => 'item_list',
    '#items' => $items,
    '#empty' => $this
      ->t('No admin comments have been entered for this order.'),
  ];
  $form['admin_comment_field'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Add an admin comment'),
  ];
  $form['admin_comment_field']['admin_comment'] = [
    '#type' => 'textarea',
    '#description' => $this
      ->t('Admin comments are only seen by store administrators.'),
  ];
  return $form;
}