View source
<?php
namespace Drupal\uc_order\Plugin\Ubercart\OrderPane;
use Drupal\Core\Form\FormStateInterface;
use Drupal\uc_order\EditableOrderPanePluginBase;
use Drupal\uc_order\OrderInterface;
abstract class AddressPaneBase extends EditableOrderPanePluginBase {
public function getClasses() {
return [
'pos-left',
];
}
public function view(OrderInterface $order, $view_mode) {
$pane = $this->pluginDefinition['id'];
$address = $order
->getAddress($pane);
return [
'#markup' => $address . '<br />' . $address
->getPhone(),
];
}
public function buildForm(OrderInterface $order, array $form, FormStateInterface $form_state) {
$pane = $this->pluginDefinition['id'];
$form['#attached']['drupalSettings'] = [
'uid' => $order
->getOwnerId(),
'paneId' => '#' . $pane . '-address-select',
'addressType' => $pane,
];
$form['address-book-image'] = [
'#theme' => 'image',
'#uri' => base_path() . drupal_get_path('module', 'uc_store') . '/images/address_book.gif',
'#title' => $this
->t('Select from address book.'),
'#alt' => $this
->t('Select from address book.'),
'#attributes' => [
'class' => 'load-address-select',
],
'#prefix' => '<div class="order-pane-icons">',
];
$form['copy-address-image'] = [
'#theme' => 'image',
'#uri' => base_path() . drupal_get_path('module', 'uc_store') . '/images/copy.gif',
'#suffix' => '</div>',
];
$form['icons'] = [
'#type' => 'markup',
'#markup' => '<div id="' . $pane . '-address-select"></div>',
];
$form['address'] = [
'#type' => 'uc_address',
'#parents' => [
$pane,
],
'#default_value' => $order
->getAddress($pane),
'#required' => FALSE,
];
return $form;
}
public function submitForm(OrderInterface $order, array &$form, FormStateInterface $form_state) {
$pane = $this->pluginDefinition['id'];
$address = $order
->getAddress($pane);
foreach ($form_state
->getValue($pane) as $key => $value) {
if (uc_address_field_enabled($key)) {
$address->{$key} = $value;
}
}
$order
->setAddress($pane, $address);
}
}