StockReportForm.php in Ubercart 8.4
File
uc_stock/src/Form/StockReportForm.php
View source
<?php
namespace Drupal\uc_stock\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\node\NodeInterface;
class StockReportForm extends FormBase {
public function getFormId() {
return 'uc_stock_report_form';
}
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL) {
$form['threshold'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Only show SKUs that are below their threshold.'),
'#default_value' => FALSE,
'#attributes' => [
'onchange' => 'this.form.submit();',
],
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Update'),
'#attributes' => [
'style' => "display:none;",
],
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getValue('threshold')) {
$form_state
->setRedirect('uc_stock.threshold');
}
else {
$form_state
->setRedirect('uc_stock.settings');
}
}
}
Classes
Name |
Description |
StockReportForm |
Displays a stock report for products with stock tracking enabled. |