diff --git a/src/Form/CollectionHarvestForm.php b/src/Form/CollectionHarvestForm.php index 32fd545..b058610 100644 --- a/src/Form/CollectionHarvestForm.php +++ b/src/Form/CollectionHarvestForm.php @@ -136,6 +136,8 @@ final class CollectionHarvestForm extends FormBase { $collections[$node->id()] = $node->label(); } } + asort($collections); + $form_state->set('collections', $collections); // Load media use taxonomy terms. $vid = 'islandora_media_use'; @@ -146,6 +148,11 @@ final class CollectionHarvestForm extends FormBase { $media_use_options[$term->tid] = $term->name; } + $form['introduction'] = [ + '#type' => 'markup', + '#markup' => '
' . $this->t("Select collection and media use to harvest. A zip of the media files will download to your computer.") . '
', + ]; + // Collection selector. $form['collection'] = [ '#type' => 'select', @@ -225,12 +232,14 @@ final class CollectionHarvestForm extends FormBase { // Store only IDs for serialization safety. $temp_store = $this->tempStoreFactory->get('islandora_collection_harvest'); - $zip_filename = 'collection_' . time() . '.zip'; + $collections = $form_state->get('collections'); + $collection_id = $form_state->getValue('collection'); + $collection_label = $collections[$collection_id] ?? 'collection'; + $sanitized_name = preg_replace('/[^a-z0-9_\-]+/i', '_', $collection_label); + $zip_filename = $sanitized_name . '_' . time() . '.zip'; + $temp_store->set($zip_filename, array_map(fn($m) => $m->id(), $media_entities)); - // Notify the user and redirect to download. - $this->messenger() - ->addStatus($this->t('Your ZIP download has been initiated. Please wait for it to start.')); $form_state->setRedirect('islandora_collection_harvest.download_zip', ['filename' => $zip_filename]); }