You are here

function fillpdf_update_8108 in FillPDF 5.0.x

Same name and namespace in other branches
  1. 8.4 fillpdf.install \fillpdf_update_8108()

Update stored FillPDF forms to the changed storage logic.

File

./fillpdf.install, line 166
Install functions for FillPDF.

Code

function fillpdf_update_8108() {
  $fillpdf_forms = FillPdfForm::loadMultiple();

  // Previously, populated PDF files were stored in the filesystem, if a
  // 'destination_path' is set. Now it is stored, if 'scheme' is set, which
  // previously was always the case. So for preexisting FillPdfForms without
  // a 'destination_path', we need to unset 'scheme' to ensure nothing changes.
  $updated_ids = [];
  foreach ($fillpdf_forms as $id => $form) {
    if (empty($form
      ->getStoragePath())) {
      $status = $form
        ->set('scheme', NULL)
        ->save();
      if ($status === SAVED_UPDATED) {
        $base_path = [
          'base_url' => \Drupal::request()
            ->getBasePath(),
        ];
        $updated_ids[] = Link::createFromRoute($id, 'entity.fillpdf_form.edit_form', [
          'fillpdf_form' => $id,
        ], $base_path)
          ->toString();
      }
    }
  }
  return new FormattableMarkup('The following FillPDF forms were updated to the changed storage logic: %list.', [
    '%list' => new FormattableMarkup(implode(', ', $updated_ids), []),
  ]);
}