Skip to content

Commit

Permalink
8.1.18
Browse files Browse the repository at this point in the history
- D8CORE-4886 improvements to the CSV form (#39)
  • Loading branch information
pookmish authored Oct 20, 2021
2 parents 2c57ee4 + da6289a commit eeeccbf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Stanford Migrate


8.x-1.18
--------------------------------------------------------------------------------
_Release Date: 2021-10-20_

- Removed unwanted status message
- D8CORE-4886 improvements to the CSV form (#39)
- Merge branch 'master' into 8.x-1.x

8.x-1.17
--------------------------------------------------------------------------------
_Release Date: 2021-10-11_
Expand Down
10 changes: 6 additions & 4 deletions src/Form/StanfordMigrateCsvImportForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,17 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'@link' => $template_link,
'%title' => $this->entity->label(),
]),
'#required' => TRUE,
'#upload_location' => 'public://csv/',
'#upload_validators' => ['file_validate_extensions' => ['csv']],
'#default_value' => array_slice($previously_uploaded_files, -1),
];
if (!empty($this->entity->get('source')['csv_help'])) {
$help = $this->entity->get('source')['csv_help'];
$form['csv_help'] = [
'#markup' => is_array($help) ? implode('<br>', $help) : $help,
];
}
unset($form['actions']['submit']);
$form['actions']['import'] = [
'#type' => 'submit',
'#value' => $this->t('Save and Import'),
Expand All @@ -142,6 +143,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['forget'] = [
'#type' => 'details',
'#title' => $this->t('Previously Uploaded Files'),
'#open' => TRUE,
];

// Create render arrays of links to the files.
Expand All @@ -157,11 +159,13 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#list_type' => 'ul',
'#items' => $previously_uploaded_files,
];
$form['forget']['previous_files_help']['#markup'] = $this->t('<p><strong>DANGER</strong>: To avoid overwriting any of the previously imported content; check the unique ID column(s) (%ids) on the previously uploaded CSV file. Each imported item (Row) should have the unique values in the columns(s).</p>', ['%ids' => implode(', ', $this->migrationPlugin->getSourceConfiguration()['ids'])]);

$form['forget']['forget_previous'] = [
'#type' => 'checkbox',
'#title' => $this->t('Forget previously imported content.'),
'#description' => $this->t('<strong>DANGER</strong>: Leave this box unchecked to update existing content based on the unique identifier column(s): %ids.', ['%ids' => implode(', ', $this->migrationPlugin->getSourceConfiguration()['ids'])]),
'#access' => $this->currentUser()->id() == 1,
];
return $form;
}
Expand Down Expand Up @@ -262,12 +266,10 @@ public function save(array $form, FormStateInterface $form_state) {
// Store the file id into state for use in the config overrider.
$state = $this->state->get("stanford_migrate.csv.$migration_id", []);
$state[] = $file_id;
$this->state->set("stanford_migrate.csv.$migration_id", array_unique($state));
$this->state->set("stanford_migrate.csv.$migration_id", $state);

$link = Link::createFromRoute($this->t('import page'), 'stanford_migrate.list')
->toString();
$this->messenger()
->addStatus($this->t('File saved. Import the contents on the @link.', ['@link' => $link]));

// Track the file usage on the migration.
$this->fileUsage->add($file, 'stanford_migrate', 'migration', $migration_id);
Expand Down
2 changes: 1 addition & 1 deletion stanford_migrate.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'Adds more functionality to migrate and migrate plus modules'
type: module
core_version_requirement: ^8.8 || ^9
package: 'Stanford'
version: 8.x-1.17
version: 8.x-1.18
dependencies:
- drupal:migrate
- migrate_plus:migrate_plus
Expand Down

0 comments on commit eeeccbf

Please sign in to comment.