Loading src/Entity/ShopifyProductVariant.php +1 −1 Changes for src/Entity/ShopifyProductVariant.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -379,7 +379,7 @@ class ShopifyProductVariant extends ContentEntityBase implements ShopifyProductV )) ->setDisplayOptions('view', array( 'label' => 'above', 'type' => 'decimal', 'type' => 'shopify_weight', 'weight' => -4, )) ->setDisplayOptions('form', array( Loading src/Plugin/Field/FieldFormatter/ShopifyWeightFormatter.php 0 → 100644 +63 −0 Changes for src/Plugin/Field/FieldFormatter/ShopifyWeightFormatter.php: 63 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * @file */ namespace Drupal\shopify\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\Plugin\Field\FieldFormatter\NumericFormatterBase; use Drupal\Core\Form\FormStateInterface; /** * Plugin implementation of the Shopify weight formatter. * * @FieldFormatter( * id = "shopify_weight", * label = @Translation("Shopify Weight"), * field_types = { * "decimal", * } * ) */ class ShopifyWeightFormatter extends NumericFormatterBase { /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { return []; } /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $elements = array(); foreach ($items as $delta => $item) { $entity = $item->getEntity(); $output = $this->numberFormat($item->value, $entity->weight_unit->value); $elements[$delta] = array('#markup' => $output); } return $elements; } /** * {@inheritdoc} */ public function settingsSummary() { $summary[] = 'Format: {{weight}}{{weight_unit}}'; $summary[] = 'Preview: ' . $this->numberFormat(1234.1234567890, 'lb'); return $summary; } /** * {@inheritdoc} */ public function numberFormat($number, $format = '') { $number = number_format($number, 2); return $number . $format; } } Loading
src/Entity/ShopifyProductVariant.php +1 −1 Changes for src/Entity/ShopifyProductVariant.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -379,7 +379,7 @@ class ShopifyProductVariant extends ContentEntityBase implements ShopifyProductV )) ->setDisplayOptions('view', array( 'label' => 'above', 'type' => 'decimal', 'type' => 'shopify_weight', 'weight' => -4, )) ->setDisplayOptions('form', array( Loading
src/Plugin/Field/FieldFormatter/ShopifyWeightFormatter.php 0 → 100644 +63 −0 Changes for src/Plugin/Field/FieldFormatter/ShopifyWeightFormatter.php: 63 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * @file */ namespace Drupal\shopify\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\Plugin\Field\FieldFormatter\NumericFormatterBase; use Drupal\Core\Form\FormStateInterface; /** * Plugin implementation of the Shopify weight formatter. * * @FieldFormatter( * id = "shopify_weight", * label = @Translation("Shopify Weight"), * field_types = { * "decimal", * } * ) */ class ShopifyWeightFormatter extends NumericFormatterBase { /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { return []; } /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $elements = array(); foreach ($items as $delta => $item) { $entity = $item->getEntity(); $output = $this->numberFormat($item->value, $entity->weight_unit->value); $elements[$delta] = array('#markup' => $output); } return $elements; } /** * {@inheritdoc} */ public function settingsSummary() { $summary[] = 'Format: {{weight}}{{weight_unit}}'; $summary[] = 'Preview: ' . $this->numberFormat(1234.1234567890, 'lb'); return $summary; } /** * {@inheritdoc} */ public function numberFormat($number, $format = '') { $number = number_format($number, 2); return $number . $format; } }