View source
<?php
namespace Drupal\uc_order\Plugin\Ubercart\OrderPane;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\uc_order\EditableOrderPanePluginBase;
use Drupal\uc_order\OrderInterface;
class CustomerInfo extends EditableOrderPanePluginBase {
public function getClasses() {
return [
'pos-left',
];
}
public function view(OrderInterface $order, $view_mode) {
if ($view_mode != 'customer') {
if ($order
->getOwnerId()) {
$build['uid'] = [
'#type' => 'link',
'#prefix' => $this
->t('Customer number') . ': ',
'#suffix' => '<br />',
'#title' => $order
->getOwnerId(),
'#url' => $order
->getOwner()
->toUrl(),
];
}
$build['primary_email'] = [
'#type' => 'link',
'#prefix' => $this
->t('E-mail address') . ': ',
'#title' => $order
->getEmail(),
'#url' => Url::fromUri('mailto:' . $order
->getEmail()),
];
return $build;
}
}
public function buildForm(OrderInterface $order, array $form, FormStateInterface $form_state) {
$form['order-view-image'] = [
'#theme' => 'image',
'#uri' => base_path() . drupal_get_path('module', 'uc_store') . '/images/order_view.gif',
'#title' => $this
->t('Search for an existing customer.'),
'#alt' => $this
->t('Search for an existing customer.'),
'#attributes' => [
'id' => 'load-customer-search',
],
'#prefix' => '<div class="order-pane-icons">',
];
$form['menu-customers-image'] = [
'#theme' => 'image',
'#uri' => base_path() . drupal_get_path('module', 'uc_store') . '/images/menu_customers_small.gif',
'#title' => $this
->t('Create a new customer.'),
'#alt' => $this
->t('Create a new customer.'),
'#attributes' => [
'id' => 'load-new-customer-form',
],
'#suffix' => '</div>',
];
$form['icons'] = [
'#type' => 'markup',
'#markup' => '<div id="customer-select"></div>',
];
$form['uid'] = [
'#type' => 'hidden',
'#default_value' => $order
->getOwnerId(),
];
$form['uid_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Customer number'),
'#default_value' => $order
->getOwnerId(),
'#maxlength' => 10,
'#size' => 10,
'#disabled' => TRUE,
];
$form['primary_email'] = [
'#type' => 'email',
'#title' => $this
->t('E-mail address'),
'#default_value' => $order
->getEmail(),
'#maxlength' => 64,
'#size' => 32,
];
return $form;
}
public function submitForm(OrderInterface $order, array &$form, FormStateInterface $form_state) {
$order
->setOwnerId($form_state
->getValue('uid'));
$order
->setEmail($form_state
->getValue('primary_email'));
}
}