ContextReactionFormBase.php in Context 8.0
File
src/Reaction/ContextReactionFormBase.php
View source
<?php
namespace Drupal\context\Reaction;
use Drupal\context\ContextInterface;
use Drupal\context\ContextReactionInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
abstract class ContextReactionFormBase extends FormBase {
protected $context;
protected $reaction;
public function buildForm(array $form, FormStateInterface $form_state, ContextInterface $context = NULL, $reaction_id = NULL) {
$this->context = $context;
$this->reaction = $this->context
->getReaction($reaction_id);
$form['reaction'] = [
'#tree' => TRUE,
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
'#button_type' => 'primary',
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->context
->save();
}
}