protected function YamlFormSubmissionStorage::doSave in YAML Form 8
Performs storage-specific saving of the entity.
Parameters
int|string $id: The original entity ID.
\Drupal\Core\Entity\EntityInterface $entity: The entity to save.
Return value
bool|int If the record insert or update failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides ContentEntityStorageBase::doSave
File
- src/
YamlFormSubmissionStorage.php, line 506
Class
- YamlFormSubmissionStorage
- Defines the form submission storage.
Namespace
Drupal\yamlformCode
protected function doSave($id, EntityInterface $entity) {
/** @var \Drupal\yamlform\YamlFormSubmissionInterface $entity */
if ($entity
->getYamlForm()
->getSetting('results_disabled')) {
return YamlFormSubmissionStorageInterface::SAVED_DISABLED;
}
$is_new = $entity
->isNew();
if (!$entity
->serial()) {
$entity
->set('serial', $this
->getNextSerial($entity));
}
$result = parent::doSave($id, $entity);
// Save data.
$this
->saveData($entity, !$is_new);
// DEBUG: dsm($entity->getState());
// Log transaction.
$yamlform = $entity
->getYamlForm();
$context = [
'@id' => $entity
->id(),
'@form' => $yamlform
->label(),
'link' => $entity
->toLink(t('Edit'), 'edit-form')
->toString(),
];
switch ($entity
->getState()) {
case YamlFormSubmissionInterface::STATE_DRAFT:
\Drupal::logger('yamlform')
->notice('@form: Submission #@id draft saved.', $context);
break;
case YamlFormSubmissionInterface::STATE_UPDATED:
\Drupal::logger('yamlform')
->notice('@form: Submission #@id updated.', $context);
break;
case YamlFormSubmissionInterface::STATE_COMPLETED:
if ($result === SAVED_NEW) {
\Drupal::logger('yamlform')
->notice('@form: Submission #@id created.', $context);
}
else {
\Drupal::logger('yamlform')
->notice('@form: Submission #@id completed.', $context);
}
break;
}
return $result;
}