UcPriceWidget.php in Ubercart 8.4
File
uc_product/src/Plugin/Field/FieldWidget/UcPriceWidget.php
View source
<?php
namespace Drupal\uc_product\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\Validator\ConstraintViolationInterface;
class UcPriceWidget extends WidgetBase {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$value = isset($items[$delta]->value) ? $items[$delta]->value : NULL;
$element += [
'#type' => 'uc_price',
'#default_value' => $value,
'#empty_zero' => FALSE,
];
return [
'value' => $element,
];
}
public function errorElement(array $element, ConstraintViolationInterface $error, array $form, FormStateInterface $form_state) {
return $element['value'];
}
}