You are here

public function TextFormat::postSave in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/TextFormat.php \Drupal\webform\Plugin\WebformElement\TextFormat::postSave()

Acts on a saved webform submission element before the insert or update hook is invoked.

Parameters

array $element: An element.

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.

Overrides WebformElementBase::postSave

File

src/Plugin/WebformElement/TextFormat.php, line 342

Class

TextFormat
Provides a 'text_format' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function postSave(array &$element, WebformSubmissionInterface $webform_submission, $update = TRUE) {
  $webform = $webform_submission
    ->getWebform();
  if ($webform
    ->isResultsDisabled()) {
    return;
  }

  // Get current value and original value for this element.
  $key = $element['#webform_key'];
  $data = $webform_submission
    ->getData();
  $value = isset($data[$key]) && isset($data[$key]['value']) ? $data[$key]['value'] : '';
  $uuids = _webform_parse_file_uuids($value);
  if ($update) {
    $original_data = $webform_submission
      ->getOriginalData();
    $original_value = isset($original_data[$key]) ? $original_data[$key]['value'] : '';
    $original_uuids = _webform_parse_file_uuids($original_value);

    // Detect file usages that should be incremented.
    $added_files = array_diff($uuids, $original_uuids);
    _webform_record_file_usage($added_files, $webform_submission
      ->getEntityTypeId(), $webform_submission
      ->id());

    // Detect file usages that should be decremented.
    $removed_files = array_diff($original_uuids, $uuids);
    _webform_delete_file_usage($removed_files, $webform_submission
      ->getEntityTypeId(), $webform_submission
      ->id(), 1);
  }
  else {
    _webform_record_file_usage($uuids, $webform_submission
      ->getEntityTypeId(), $webform_submission
      ->id());
  }
}