public function EntityQueryMapImportForm::save in GraphQL 8.3
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
File
- src/
Form/ EntityQueryMapImportForm.php, line 66
Class
- EntityQueryMapImportForm
- Form controller for GraphQL query map forms.
Namespace
Drupal\graphql\FormCode
public function save(array $form, FormStateInterface $formState) {
$file = $formState
->get('file');
$json = file_get_contents($file
->getFileUri());
/** @var \Drupal\graphql\Entity\QueryMapInterface $entity */
$entity = $this->entity;
$entity
->set('version', sha1($json));
$entity
->set('map', array_flip((array) json_decode($json)));
$entity
->save();
$this
->messenger()
->addMessage($this
->t('Saved the query map version %id.', [
'%id' => $entity
->id(),
]));
$formState
->setRedirect('entity.graphql_query_map.collection');
}