public function RulesAddEditForm::submitForm in Custom filter 2.0.x
Same name and namespace in other branches
- 8 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 169
Class
- RulesAddEditForm
- Defines a form to add/edit the rules.
Namespace
Drupal\customfilter\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity = CustomFilter::load($form_state
->getValue('fid'));
$item = [
'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':
print 'edit';
print_r($item);
$this->entity
->updateRule($item);
$this->entity
->save();
break;
case 'add':
$this->entity
->addRule($item);
$this->entity
->save();
break;
}
$form_state
->setRedirect('customfilter.rules.list', [
'customfilter' => $form_state
->getValue('fid'),
]);
}