/** * {@inheritdoc} */ public function render(ResultRow $values) { if ($this->options['format'] == 'uc_length') { $value = $this->getValue($values); if (is_null($value) || $value == 0 && $this->options['empty_zero']) { return ''; } return uc_length_format($value, $values->{$this->aliases['length_units']}); } else { return parent::render($values); } }
/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $elements = []; foreach ($items as $delta => $item) { $dimensions = []; foreach (['length', 'width', 'height'] as $dimension) { if ($item->{$dimension}) { $dimensions[] = uc_length_format($item->{$dimension}, $item->units); } } if ($dimensions) { $elements[$delta] = array('#markup' => implode(' × ', $dimensions)); } } return $elements; }
public function testProductNodeForm() { $this->drupalGet('node/add/product'); $fields = array('model[0][value]', 'price[0][value]', 'shippable[value]', 'weight[0][value]', 'weight[0][units]', 'dimensions[0][length]', 'dimensions[0][width]', 'dimensions[0][height]', 'dimensions[0][units]', 'files[uc_product_image_0][]'); foreach ($fields as $field) { $this->assertFieldByName($field, NULL); } $title_key = 'title[0][value]'; $body_key = 'body[0][value]'; // Make a node with those fields. $edit = array($title_key => $this->randomMachineName(32), $body_key => $this->randomMachineName(64), 'model[0][value]' => $this->randomMachineName(8), 'price[0][value]' => mt_rand(1, 150), 'shippable[value]' => mt_rand(0, 1), 'weight[0][value]' => mt_rand(1, 50), 'weight[0][units]' => array_rand(array('lb' => t('Pounds'), 'kg' => t('Kilograms'), 'oz' => t('Ounces'), 'g' => t('Grams'))), 'dimensions[0][length]' => mt_rand(1, 50), 'dimensions[0][width]' => mt_rand(1, 50), 'dimensions[0][height]' => mt_rand(1, 50), 'dimensions[0][units]' => array_rand(array('in' => t('Inches'), 'ft' => t('Feet'), 'cm' => t('Centimeters'), 'mm' => t('Millimeters')))); $this->drupalPostForm('node/add/product', $edit, 'Save'); $this->assertText(t('Product @title has been created.', ['@title' => $edit[$title_key]]), 'Product created.'); $this->assertText($edit[$body_key], 'Product body found.'); $this->assertText($edit['model[0][value]'], 'Product model found.'); $this->assertNoUniqueText(uc_currency_format($edit['price[0][value]']), 'Product price found.'); $this->assertText(uc_weight_format($edit['weight[0][value]'], $edit['weight[0][units]']), 'Product weight found.'); $this->assertText(uc_length_format($edit['dimensions[0][length]'], $edit['dimensions[0][units]']), 'Product length found.'); $this->assertText(uc_length_format($edit['dimensions[0][width]'], $edit['dimensions[0][units]']), 'Product width found.'); $this->assertText(uc_length_format($edit['dimensions[0][height]'], $edit['dimensions[0][units]']), 'Product height found.'); $elements = $this->xpath('//body[contains(@class, "uc-product-node")]'); $this->assertEqual(count($elements), 1, 'Product page contains body CSS class.'); // Update the node fields. $edit = array($title_key => $this->randomMachineName(32), $body_key => $this->randomMachineName(64), 'model[0][value]' => $this->randomMachineName(8), 'price[0][value]' => mt_rand(1, 150), 'shippable[value]' => mt_rand(0, 1), 'weight[0][value]' => mt_rand(1, 50), 'weight[0][units]' => array_rand(array('lb' => t('Pounds'), 'kg' => t('Kilograms'), 'oz' => t('Ounces'), 'g' => t('Grams'))), 'dimensions[0][length]' => mt_rand(1, 50), 'dimensions[0][width]' => mt_rand(1, 50), 'dimensions[0][height]' => mt_rand(1, 50), 'dimensions[0][units]' => array_rand(array('in' => t('Inches'), 'ft' => t('Feet'), 'cm' => t('Centimeters'), 'mm' => t('Millimeters')))); $this->clickLink('Edit'); $this->drupalPostForm(NULL, $edit, 'Save'); $this->assertText(t('Product @title has been updated.', ['@title' => $edit[$title_key]]), 'Product updated.'); $this->assertText($edit[$body_key], 'Updated product body found.'); $this->assertText($edit['model[0][value]'], 'Updated product model found.'); $this->assertNoUniqueText(uc_currency_format($edit['price[0][value]']), 'Updated product price found.'); $this->assertText(uc_weight_format($edit['weight[0][value]'], $edit['weight[0][units]']), 'Product weight found.'); $this->assertText(uc_length_format($edit['dimensions[0][length]'], $edit['dimensions[0][units]']), 'Product length found.'); $this->assertText(uc_length_format($edit['dimensions[0][width]'], $edit['dimensions[0][units]']), 'Product width found.'); $this->assertText(uc_length_format($edit['dimensions[0][height]'], $edit['dimensions[0][units]']), 'Product height found.'); $this->clickLink('Delete'); $this->drupalPostForm(NULL, [], 'Delete'); $this->assertText(t('Product @title has been deleted.', ['@title' => $edit[$title_key]]), 'Product deleted.'); }
/** * Displays the details of a package. * * @param $package * The package object. * * @return array * A render array. */ public function viewPackage($package) { $shipment = Shipment::load($package->sid); $build = array('#type' => 'container', '#attributes' => array('class' => array('order-pane', 'pos-left'))); $build['title'] = array('#type' => 'container', '#markup' => $this->t('Package %id:', ['%id' => $package->package_id]), '#attributes' => array('class' => array('order-pane-title'))); $rows = array(); $rows[] = array($this->t('Contents:'), Xss::filterAdmin($package->description)); if ($shipment) { $methods = \Drupal::moduleHandler()->invokeAll('uc_fulfillment_method'); if (isset($methods[$shipment->shipping_method])) { $pkg_type = $methods[$shipment->shipping_method]['ship']['pkg_types'][$package->pkg_type]; } } $rows[] = array($this->t('Package type:'), isset($pkg_type) ? $pkg_type : SafeMarkup::checkPlain($package->pkg_type)); if ($package->length && $package->width && $package->height) { $rows[] = array($this->t('Dimensions:'), $this->t('@l x @w x @h', ['@l' => uc_length_format($package->length), '@w' => uc_length_format($package->width), '@h' => uc_length_format($package->height)])); } $rows[] = array($this->t('Insured value:'), array('data' => array('#theme' => 'uc_price', '#price' => $package->value))); if ($package->tracking_number) { $rows[] = array($this->t('Tracking number:'), SafeMarkup::checkPlain($package->tracking_number)); } if ($shipment && isset($package->label_image) && file_exists($package->label_image->uri)) { $rows[] = array($this->t('Label:'), Link::fromTextAndUrl($this->t('Click to view.'), Url::fromUri('admin/store/orders/' . $package->order_id . '/shipments/labels/' . $shipment->shipping_method . '/' . $package->label_image->uri))->toString()); } else { $rows[] = array($this->t('Label:'), $this->t('n/a')); } $build['package'] = array('#theme' => 'table', '#rows' => $rows, 'attributes' => array('style' => 'width:auto;')); return $build; }