public function WorkflowRepository::insert in Forms Steps 8
Save an entry in the database.
Exception handling is shown in this example. It could be simplified without the try/catch blocks, but since an insert will throw an exception and terminate your application if the exception is not handled, it is best to employ try/catch.
Parameters
array $entry: An array containing all the fields of the database record.
Return value
int The number of updated rows.
Throws
\Exception When the database insert fails.
See also
File
- src/
Repository/ WorkflowRepository.php, line 61
Class
- WorkflowRepository
- Class WorkflowRepository.
Namespace
Drupal\forms_steps\RepositoryCode
public function insert(array $entry) {
$return_value = NULL;
try {
$return_value = $this->connection
->insert(self::FORMS_STEPS_WORKFLOW_DB)
->fields($entry)
->execute();
} catch (\Exception $e) {
$this
->messenger()
->addMessage($this
->t('db_insert failed. Message = %message', [
'%message' => $e
->getMessage(),
]), 'error');
}
return $return_value;
}