You are here

public static function ContactStorageExportTempstore::setTempstore in Contact Storage Export 8

Save the data to the temp store.

Parameters

int $fid: The file id.

string $filename: The filename.

Return value

int|mixed The tempstore key.

Throws

\Drupal\Core\TempStore\TempStoreException

1 call to ContactStorageExportTempstore::setTempstore()
ContactStorageExportBatches::finishBatch in src/ContactStorageExportBatches.php
Finish callback for the batch set the export form.

File

src/ContactStorageExportTempstore.php, line 25

Class

ContactStorageExportTempstore
Class ContactStorageExportTempstore.

Namespace

Drupal\contact_storage_export

Code

public static function setTempstore($fid, $filename) {

  /** @var \Drupal\Core\Tempstore\PrivateTempStore $tempstore */
  $tempstore = \Drupal::service('tempstore.private')
    ->get('contact_storage_export');

  // Possibly have more than one export running at a time, set unique key.
  $data = [];
  $key = 0;
  if (is_array($data)) {
    $data = self::cleanTempstoreData($data);
    if ($keys = array_keys($data)) {
      $key = max($keys) + 1;
    }
  }

  // Set data.
  $data[$key] = [
    'created' => time(),
    'fid' => $fid,
    'filename' => $filename,
  ];

  // Save tempstore.
  $tempstore
    ->set('data', $data);
  return $key;
}