CurrencyAmountElement.php in Currency 8.3
File
modules/currency_test/src/CurrencyAmountElement.php
View source
<?php
namespace Drupal\currency_test;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
class CurrencyAmountElement implements FormInterface {
public function getFormId() {
return 'currency_test_currency_amount_element';
}
public function buildForm(array $form, FormStateInterface $form_state, $minimum_amount = NULL, $maximum_amount = NULL, $currency_code = NULL) {
$form['container'] = array(
'#tree' => TRUE,
);
$form['container']['amount'] = array(
'#limit_currency_codes' => $currency_code ? array(
$currency_code,
) : array(),
'#type' => 'currency_amount',
'#title' => t('Foo amount'),
'#minimum_amount' => $minimum_amount,
'#maximum_amount' => $maximum_amount,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
\Drupal::state()
->set('currency_test_currency_amount_element', $values['container']['amount']);
}
}