<?php

/**
 * @file
 * Contains Drupal\firma\Form\FirmaForm.
 */

namespace Drupal\firma\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;


class FirmaForm extends FormBase {

  public function getFormId() {
    return 'firma_form';
  }

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Your name'),
      '#placeholder' => t('Your name'),
      '#required' => TRUE,
    );
    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
      '#button_type' => 'primary',
    );
    return $form;
  }

  public function validateForm(array &$form, FormStateInterface $form_state) {
    if (strlen($form_state->getValue('name')) < 3) {
      $form_state->setErrorByName('name', t("Too short... It doesn't seem to be a real name."));
    }

  }

  public function submitForm(array &$form, FormStateInterface $form_state) {
    drupal_set_message(
      t('Name @name is @length characters long.',
        array(
          '@name' => $form_state->getValue('name'),
          '@length' => strlen($form_state->getValue('name')),
        )
      )
    );
  }

}
