Skip to content

Instantly share code, notes, and snippets.

@cyberlex404
Created June 2, 2017 21:52
Show Gist options
  • Select an option

  • Save cyberlex404/f9fc90d5b55121796151598644e5a6ae to your computer and use it in GitHub Desktop.

Select an option

Save cyberlex404/f9fc90d5b55121796151598644e5a6ae to your computer and use it in GitHub Desktop.
Event
<?php
namespace Drupal\expert_questions\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
/**
* Class TestFormEvent.
*
* @package Drupal\expert_questions\Form
*/
class TestFormEvent extends FormBase {
/**
* Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher definition.
*
* @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
*/
protected $eventDispatcher;
/**
* Constructs a new TestFormEvent object.
*/
public function __construct(
ContainerAwareEventDispatcher $event_dispatcher
) {
$this->eventDispatcher = $event_dispatcher;
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('event_dispatcher')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'test_form_event';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Display result.
foreach ($form_state->getValues() as $key => $value) {
drupal_set_message($key . ': ' . $value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment