You are here

class CurrencySignElement in Currency 8.3

Provides a form to test the currency_sign element.

Hierarchy

Expanded class hierarchy of CurrencySignElement

1 string reference to 'CurrencySignElement'
currency_test.routing.yml in modules/currency_test/currency_test.routing.yml
modules/currency_test/currency_test.routing.yml

File

modules/currency_test/src/CurrencySignElement.php, line 11

Namespace

Drupal\currency_test
View source
class CurrencySignElement implements FormInterface {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'currency_test_currency_sign_element';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $currency_code = NULL, $currency_sign = NULL) {

    // Nest the element to make sure that works.
    $form['container'] = array(
      '#tree' => TRUE,
    );
    $form['container']['sign'] = array(
      '#currency_code' => $currency_code ? $currency_code : FALSE,
      '#default_value' => $currency_sign,
      '#type' => 'currency_sign',
      '#title' => t('Foo sign'),
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state
      ->getValues();
    \Drupal::state()
      ->set('currency_test_currency_sign_element', $values['container']['sign']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CurrencySignElement::buildForm public function Form constructor. Overrides FormInterface::buildForm
CurrencySignElement::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
CurrencySignElement::submitForm public function Form submission handler. Overrides FormInterface::submitForm
CurrencySignElement::validateForm public function Form validation handler. Overrides FormInterface::validateForm