public function Test::submitForm in farmOS 2.x
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides QuickFormBase::submitForm
File
- modules/
core/ quick/ tests/ modules/ farm_quick_test/ src/ Plugin/ QuickForm/ Test.php, line 49
Class
- Test
- Test quick form.
Namespace
Drupal\farm_quick_test\Plugin\QuickFormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// Get the submitted value.
$value = $form_state
->getValue('test');
// Create an asset.
$asset = $this
->createAsset([
'type' => 'test',
'name' => $value,
]);
// Create a log.
$log = $this
->createLog([
'type' => 'test',
'name' => $value,
'quantity' => [
[
'measure' => 'count',
'value' => $value,
'units' => $this
->t('tests'),
],
],
]);
// Create a quantity.
$quantity = $this
->createQuantity([
'measure' => 'count',
'value' => $value,
'units' => $this
->t('tests'),
'label' => $this
->t('test label'),
]);
// Create a term.
$term1 = $this
->createTerm([
'name' => 'test1',
'vocabulary' => 'test',
]);
// Create a term with createOrLoadTerm().
$term2 = $this
->createOrLoadTerm('test2', 'test');
// Load a term with createOrLoadTerm().
$term3 = $this
->createOrLoadTerm('test2', 'test');
// Save entities to form state for automated test review.
$storage = [];
$storage['assets'][] = $asset;
$storage['logs'][] = $log;
$storage['quantities'][] = $quantity;
$storage['terms'][] = $term1;
$storage['terms'][] = $term2;
$storage['terms'][] = $term3;
$form_state
->setStorage($storage);
}