protected function WebformSubmissionStorage::doPostSave in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformSubmissionStorage.php \Drupal\webform\WebformSubmissionStorage::doPostSave()
Performs post save entity processing.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The saved entity.
bool $update: Specifies whether the entity is being updated or created.
Overrides ContentEntityStorageBase::doPostSave
File
- src/
WebformSubmissionStorage.php, line 1020
Class
- WebformSubmissionStorage
- Defines the webform submission storage.
Namespace
Drupal\webformCode
protected function doPostSave(EntityInterface $entity, $update) {
/** @var \Drupal\webform\WebformSubmissionInterface $entity */
parent::doPostSave($entity, $update);
$webform = $entity
->getWebform();
if ($webform
->hasSubmissionLog()) {
// Log webform submission events to the 'webform_submission' log.
$context = [
'@title' => $entity
->label(),
'link' => $entity
->id() ? $entity
->toLink($this
->t('Edit'), 'edit-form')
->toString() : NULL,
'webform_submission' => $entity,
];
switch ($entity
->getState()) {
case WebformSubmissionInterface::STATE_DRAFT_UPDATED:
case WebformSubmissionInterface::STATE_DRAFT_CREATED:
if ($update) {
$message = '@title draft updated.';
$context['operation'] = 'draft updated';
}
else {
$message = '@title draft created.';
$context['operation'] = 'draft created';
}
break;
case WebformSubmissionInterface::STATE_COMPLETED:
if ($update) {
$message = '@title completed using saved draft.';
$context['operation'] = 'submission completed';
}
else {
$message = '@title created.';
$context['operation'] = 'submission created';
}
break;
case WebformSubmissionInterface::STATE_CONVERTED:
$message = '@title converted from anonymous to @user.';
$context['operation'] = 'submission converted';
$context['@user'] = $entity
->getOwner()
->label();
break;
case WebformSubmissionInterface::STATE_UPDATED:
$message = '@title updated.';
$context['operation'] = 'submission updated';
break;
case WebformSubmissionInterface::STATE_UNSAVED:
$message = '@title submitted.';
$context['operation'] = 'submission submitted';
break;
case WebformSubmissionInterface::STATE_LOCKED:
$message = '@title locked.';
$context['operation'] = 'submission locked';
break;
default:
throw new \Exception('Unexpected webform submission state');
}
$this->loggerFactory
->get('webform_submission')
->notice($message, $context);
}
elseif (!$webform
->getSetting('results_disabled')) {
// Log general events to the 'webform'.
switch ($entity
->getState()) {
case WebformSubmissionInterface::STATE_DRAFT_CREATED:
$message = '@title draft created.';
break;
case WebformSubmissionInterface::STATE_DRAFT_UPDATED:
$message = '@title draft updated.';
break;
case WebformSubmissionInterface::STATE_UPDATED:
$message = '@title updated.';
break;
case WebformSubmissionInterface::STATE_COMPLETED:
$message = $update ? '@title completed.' : '@title created.';
break;
default:
$message = NULL;
break;
}
if ($message) {
$context = [
'@id' => $entity
->id(),
'@title' => $entity
->label(),
'link' => $entity
->id() ? $entity
->toLink($this
->t('Edit'), 'edit-form')
->toString() : NULL,
];
$this->loggerFactory
->get('webform')
->notice($message, $context);
}
}
$this
->invokeWebformElements('postSave', $entity, $update);
$this
->invokeWebformHandlers('postSave', $entity, $update);
}