PriceDefaultWidget.php in Price 3.x
File
src/Plugin/Field/FieldWidget/PriceDefaultWidget.php
View source
<?php
namespace Drupal\price\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
class PriceDefaultWidget extends WidgetBase {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element['#type'] = 'price_price';
if (!$items[$delta]
->isEmpty()) {
$element['#default_value'] = $items[$delta]
->toPrice()
->toArray();
}
$element['#available_currencies'] = array_filter($this
->getFieldSetting('available_currencies'));
return $element;
}
}