SimpleStockTransactionWidget.php in Commerce Stock 8
File
modules/field/src/Plugin/Field/FieldWidget/SimpleStockTransactionWidget.php
View source
<?php
namespace Drupal\commerce_stock_field\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
class SimpleStockTransactionWidget extends StockLevelWidgetBase {
protected function getHelpText() {
return $this
->t('Simple stock adjustments right on the product edit form. We recommend using this widget. Learn in the docs why.');
}
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
if ($this
->isDefaultValueWidget($form_state)) {
$element['#description'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => $this
->t('Default values for stock transactions are not supported.'),
];
return $element;
}
return parent::formElement($items, $delta, $element, $form, $form_state);
}
}