public static function PriceItem::generateSampleValue in Commerce Core 8.2
Generates placeholder field values.
Useful when populating site with placeholder content during site building or profiling.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.
Return value
array An associative array of values.
Overrides FieldItemBase::generateSampleValue
1 call to PriceItem::generateSampleValue()
- PriceItemGeneratedSampleValueTest::testGeneratedSampleValue in modules/
price/ tests/ src/ Kernel/ PriceItemGeneratedSampleValueTest.php - Tests the generated sample value.
File
- modules/
price/ src/ Plugin/ Field/ FieldType/ PriceItem.php, line 76
Class
- PriceItem
- Plugin implementation of the 'commerce_price' field type.
Namespace
Drupal\commerce_price\Plugin\Field\FieldTypeCode
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$available_currencies = array_filter($field_definition
->getSetting('available_currencies'));
if (count($available_currencies) === 0) {
/** @var \Drupal\commerce_price\Entity\CurrencyInterface[] $currencies */
$currencies = \Drupal::entityTypeManager()
->getStorage('commerce_currency')
->loadMultiple();
$sample_currency_code = reset($currencies)
->getCurrencyCode();
}
else {
$sample_currency_code = reset($available_currencies);
}
return [
'number' => '9.99',
'currency_code' => $sample_currency_code,
];
}