class PriceNumberNormalizer in Commerce Core 8.2
Normalizes price field number properties.
MySQL will store the number with trailing zeros, causing comparison problems.
@todo remove after https://www.drupal.org/project/drupal/issues/3163853
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\serialization\Normalizer\PrimitiveDataNormalizer uses SerializedColumnNormalizerTrait
- class \Drupal\commerce_price_test\Normalizer\PriceNumberNormalizer
- class \Drupal\serialization\Normalizer\PrimitiveDataNormalizer uses SerializedColumnNormalizerTrait
Expanded class hierarchy of PriceNumberNormalizer
1 string reference to 'PriceNumberNormalizer'
- commerce_price_test.services.yml in modules/
price/ tests/ modules/ commerce_price_test/ commerce_price_test.services.yml - modules/price/tests/modules/commerce_price_test/commerce_price_test.services.yml
1 service uses PriceNumberNormalizer
- commerce_test.price_number_normalizer in modules/
price/ tests/ modules/ commerce_price_test/ commerce_price_test.services.yml - Drupal\commerce_price_test\Normalizer\PriceNumberNormalizer
File
- modules/
price/ tests/ modules/ commerce_price_test/ src/ Normalizer/ PriceNumberNormalizer.php, line 16
Namespace
Drupal\commerce_price_test\NormalizerView source
class PriceNumberNormalizer extends PrimitiveDataNormalizer {
/**
* {@inheritdoc}
*/
protected $supportedInterfaceOrClass = StringData::class;
/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = NULL) {
$supported = parent::supportsNormalization($data, $format);
return $supported && $data instanceof StringData && $data
->getParent() instanceof PriceItem && $data
->getName() === 'number';
}
/**
* {@inheritdoc}
*/
public function normalize($object, $format = NULL, array $context = []) {
$data = parent::normalize($object, $format, $context);
return number_format($data, 2);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
NormalizerBase:: |
protected | property | List of formats which supports (de-)normalization. | 3 |
NormalizerBase:: |
protected | function | Adds cacheability if applicable. | |
NormalizerBase:: |
protected | function | Checks if the provided format is supported by this normalizer. | 2 |
NormalizerBase:: |
public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | 1 |
PriceNumberNormalizer:: |
protected | property |
The interface or class that this Normalizer supports. Overrides PrimitiveDataNormalizer:: |
|
PriceNumberNormalizer:: |
public | function |
Normalizes an object into a set of arrays/scalars. Overrides PrimitiveDataNormalizer:: |
|
PriceNumberNormalizer:: |
public | function |
Checks whether the given class is supported for normalization by this normalizer. Overrides NormalizerBase:: |
|
SerializedColumnNormalizerTrait:: |
protected | function | Checks if there is a serialized string for a column. | |
SerializedColumnNormalizerTrait:: |
protected | function | Checks if the data contains string value for serialize column. | |
SerializedColumnNormalizerTrait:: |
protected | function | Gets the names of all properties the plugin treats as serialized data. | |
SerializedColumnNormalizerTrait:: |
protected | function | Gets the names of all serialized properties. |