View source
<?php
namespace Drupal\uc_cart\Plugin\Ubercart\CheckoutPane;
use Drupal\Core\Form\FormStateInterface;
use Drupal\uc_cart\CheckoutPanePluginBase;
use Drupal\uc_order\OrderInterface;
class OrderCommentsPane extends CheckoutPanePluginBase {
public function view(OrderInterface $order, array $form, FormStateInterface $form_state) {
$build['#description'] = $this
->t('Use this area for special instructions or questions regarding your order.');
if ($order
->id()) {
$default = \Drupal::database()
->query('SELECT message FROM {uc_order_comments} WHERE order_id = :id', [
':id' => $order
->id(),
])
->fetchField();
}
else {
$default = NULL;
}
$build['comments'] = [
'#type' => 'textarea',
'#title' => $this
->t('Order comments'),
'#default_value' => $default,
];
return $build;
}
public function process(OrderInterface $order, array $form, FormStateInterface $form_state) {
\Drupal::database()
->delete('uc_order_comments')
->condition('order_id', $order
->id())
->execute();
if (!$form_state
->isValueEmpty([
'panes',
'comments',
'comments',
])) {
uc_order_comment_save($order
->id(), 0, $form_state
->getValue([
'panes',
'comments',
'comments',
]), 'order', uc_order_state_default('post_checkout'), TRUE);
}
return TRUE;
}
public function review(OrderInterface $order) {
$review = NULL;
$result = \Drupal::database()
->query('SELECT message FROM {uc_order_comments} WHERE order_id = :id', [
':id' => $order
->id(),
]);
if ($comment = $result
->fetchObject()) {
$review[] = [
'title' => $this
->t('Comment'),
'data' => [
'#markup' => $comment->message,
],
];
}
return $review;
}
}