function RestExampleClientEdit::submitForm
Same name in other branches
- 3.x modules/rest_example/src/Form/RestExampleClientEdit.php \Drupal\rest_example\Form\RestExampleClientEdit::submitForm()
Throws
\GuzzleHttp\Exception\GuzzleException
Overrides FormInterface::submitForm
File
-
modules/
rest_example/ src/ Form/ RestExampleClientEdit.php, line 112
Class
- RestExampleClientEdit
- Edit or create a new node on a remote Drupal site.
Namespace
Drupal\rest_example\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$node_id = $form_state->get('node_id');
$node_type = $form_state->get('node_type');
$form_values = $form_state->getValues();
$node = [
'nid' => $node_id,
'title' => $form_values['title'],
'type' => $node_type,
];
if (is_null($node_id)) {
$this->client
->create($node);
}
else {
$this->client
->update($node);
}
$this->messenger()
->addStatus($this->t('Node was successfully created'));
$form_state->setRedirect('rest_example.client_actions_index');
}