public function RulesAddEditForm::submitForm in Custom filter 8
Same name and namespace in other branches
- 2.0.x src/Form/RulesAddEditForm.php \Drupal\customfilter\Form\RulesAddEditForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ RulesAddEditForm.php, line 177
Class
- RulesAddEditForm
- Defines a form to add/edit the rules.
Namespace
Drupal\customfilter\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity = entity_load("customfilter", $form_state
->getValue('fid'));
$item = array(
'rid' => $form_state
->getValue('rid'),
'prid' => $form_state
->getValue('prid'),
'fid' => $this->entity
->id(),
'name' => $form_state
->getValue('name'),
'description' => $form_state
->getValue('description'),
'enabled' => $form_state
->getValue('enabled'),
'matches' => $form_state
->getValue('matches'),
'pattern' => $form_state
->getValue('pattern'),
'replacement' => $form_state
->getValue('replacement'),
'code' => $form_state
->getValue('code'),
'weight' => $form_state
->getValue('weight'),
);
switch ($form_state
->getValue('operation')) {
case 'edit':
$this->entity
->updateRule($item);
$this->entity
->save();
break;
case 'add':
$this->entity
->addRule($item);
$this->entity
->save();
break;
}
$form_state
->setRedirect('customfilter.rules.list', array(
'customfilter' => $form_state
->getValue('fid'),
));
}