/** * {@inheritdoc} */ public function view(OrderInterface $order, $view_mode) { // @todo Simplify this or replace with Views if ($view_mode == 'customer') { $comments = uc_order_comments_load($order->id()); $statuses = OrderStatus::loadMultiple(); $header = array($this->t('Date'), $this->t('Status'), $this->t('Message')); $rows[] = array(array('data' => \Drupal::service('date.formatter')->format($order->created->value, 'uc_store'), 'class' => array('date')), array('data' => '-', 'class' => array('status')), array('data' => $this->t('Order created.'), 'class' => array('message'))); if (count($comments) > 0) { foreach ($comments as $comment) { $rows[] = array(array('data' => \Drupal::service('date.formatter')->format($comment->created, 'uc_store'), 'class' => array('date')), array('data' => array('#plain_text' => $statuses[$comment->order_status]->getName()), 'class' => array('status')), array('data' => array('#markup' => $comment->message), 'class' => array('message'))); } } $build = array('#theme' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => array('class' => array('uc-order-comments'))); } else { $build = array('#theme' => 'table', '#header' => array(array('data' => $this->t('Date'), 'class' => array('date')), array('data' => $this->t('User'), 'class' => array('user', RESPONSIVE_PRIORITY_LOW)), array('data' => $this->t('Notified'), 'class' => array('notified')), array('data' => $this->t('Status'), 'class' => array('status', RESPONSIVE_PRIORITY_LOW)), array('data' => $this->t('Comment'), 'class' => array('message'))), '#rows' => array(), '#attributes' => array('class' => array('order-pane-table uc-order-comments')), '#empty' => $this->t('This order has no comments associated with it.')); $comments = uc_order_comments_load($order->id()); $statuses = OrderStatus::loadMultiple(); foreach ($comments as $comment) { $icon = $comment->notified ? 'true-icon.gif' : 'false-icon.gif'; $build['#rows'][] = array(array('data' => \Drupal::service('date.formatter')->format($comment->created, 'short'), 'class' => array('date')), array('data' => array('#theme' => 'uc_uid', '#uid' => $comment->uid), 'class' => array('user')), array('data' => array('#theme' => 'image', '#uri' => drupal_get_path('module', 'uc_order') . '/images/' . $icon), 'class' => array('notified')), array('data' => array('#plain_text' => $statuses[$comment->order_status]->getName()), 'class' => array('status')), array('data' => array('#markup' => $comment->message), 'class' => array('message'))); } } return $build; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $states = uc_order_state_options_list(); $statuses = OrderStatus::loadMultiple(); $form['order_states'] = array('#type' => 'details', '#title' => t('Order states')); $form['order_states']['order_states'] = array('#type' => 'table', '#header' => array(t('State'), t('Default order status'))); foreach ($states as $state_id => $title) { $form['order_states']['order_states'][$state_id]['title'] = array('#markup' => $title); // Create the select box for specifying a default status per order state. $options = array(); foreach ($statuses as $status) { if ($state_id == $status->getState()) { $options[$status->id()] = $status->getName(); } } if (empty($options)) { $form['order_states']['order_states'][$state_id]['default'] = array('#markup' => t('- N/A -')); } else { $form['order_states']['order_states'][$state_id]['default'] = array('#type' => 'select', '#options' => $options, '#default_value' => uc_order_state_default($state_id)); } } $form['order_statuses'] = array('#type' => 'details', '#title' => t('Order statuses'), '#open' => TRUE); $form['order_statuses']['order_statuses'] = array('#type' => 'table', '#header' => array(t('ID'), t('Title'), t('List position'), t('State'), t('Remove'))); foreach ($statuses as $status) { $form['order_statuses']['order_statuses'][$status->id()]['id'] = array('#markup' => $status->id()); $form['order_statuses']['order_statuses'][$status->id()]['name'] = array('#type' => 'textfield', '#default_value' => $status->getName(), '#size' => 32, '#required' => TRUE); $form['order_statuses']['order_statuses'][$status->id()]['weight'] = array('#type' => 'weight', '#delta' => 20, '#default_value' => $status->getWeight()); if ($status->isLocked()) { $form['order_statuses']['order_statuses'][$status->id()]['state'] = array('#markup' => $states[$status->getState()]); } else { $form['order_statuses']['order_statuses'][$status->id()]['state'] = array('#type' => 'select', '#options' => $states, '#default_value' => $status->getState()); $form['order_statuses']['order_statuses'][$status->id()]['remove'] = array('#type' => 'checkbox'); } } return parent::buildForm($form, $form_state); }