-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
20 changed files
with
1,171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
modules/custom/az_publication/az_publication_bibtex/az_publication_bibtex.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: 'Quickstart Publication BibTeX Import' | ||
type: module | ||
description: 'Allows BibTeX import of publications' | ||
core_version_requirement: ^9 || ^10 | ||
package: 'The University of Arizona - Experimental' | ||
dependencies: | ||
- 'az_core:az_core' | ||
- 'az_publication:az_publication' | ||
- 'az_publication_import:az_publication_import' | ||
- migrate | ||
- migrate_plus | ||
- migrate_tools |
6 changes: 6 additions & 0 deletions
6
modules/custom/az_publication/az_publication_bibtex/az_publication_bibtex.links.menu.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
az_publication_bibtex.import_bibtex: | ||
title: 'Import BibTeX Publication' | ||
description: 'Import a Quickstart publication from a BibTeX document.' | ||
route_name: az_publication_bibtex.az_publication_bibtex_import_form | ||
parent: az_publication_import.admin.content | ||
weight: 0 |
7 changes: 7 additions & 0 deletions
7
modules/custom/az_publication/az_publication_bibtex/az_publication_bibtex.routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
az_publication_bibtex.az_publication_bibtex_import_form: | ||
path: '/admin/content/az-publication/import/bibtex' | ||
defaults: | ||
_form: '\Drupal\az_publication_bibtex\Form\AZPublicationBibtexForm' | ||
_title: 'BibTeX Import' | ||
requirements: | ||
_permission: 'administer quickstart configuration' |
179 changes: 179 additions & 0 deletions
179
...s/custom/az_publication/az_publication_bibtex/migrations/az_publication_bibtex_import.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
id: az_publication_bibtex_import | ||
label: AZ Quickstart Publication BibTeX Import | ||
migration_tags: | ||
- Publications | ||
source: | ||
plugin: url | ||
data_fetcher_plugin: file | ||
data_parser_plugin: az_bibtex | ||
urls: [] | ||
ids: | ||
citation_key: | ||
type: string | ||
fields: | ||
- | ||
name: _type | ||
selector: _type | ||
- | ||
name: citation_key | ||
selector: citation-key | ||
- | ||
name: title | ||
selector: title | ||
- | ||
name: author | ||
selector: author | ||
- | ||
name: publisher | ||
selector: publisher | ||
- | ||
name: institution | ||
selector: institution | ||
- | ||
name: school | ||
selector: school | ||
- | ||
name: location | ||
selector: location | ||
- | ||
name: volume | ||
selector: volume | ||
- | ||
name: pages | ||
selector: pages | ||
- | ||
name: number | ||
selector: number | ||
- | ||
name: booktitle | ||
selector: booktitle | ||
- | ||
name: journaltitle | ||
selector: journaltitle | ||
- | ||
name: journal | ||
selector: journal | ||
- | ||
name: annotation | ||
selector: annotation | ||
- | ||
name: abstract | ||
selector: abstract | ||
- | ||
name: url | ||
selector: url | ||
- | ||
name: doi | ||
selector: doi | ||
- | ||
name: version | ||
selector: version | ||
- | ||
name: datetype | ||
selector: _date_type | ||
- | ||
name: date | ||
selector: _date | ||
|
||
process: | ||
type: | ||
plugin: default_value | ||
default_value: az_publication | ||
field_az_publication_type: | ||
plugin: static_map | ||
source: _type | ||
map: | ||
article: article-journal | ||
book: book | ||
booklet: pamphlet | ||
collection: collection | ||
conference: paper-conference | ||
inbook: book | ||
incollection: entry | ||
inproceedings: paper-conference | ||
manual: pamphlet | ||
mastersthesis: thesis | ||
misc: post | ||
online: webpage | ||
patent: patent | ||
periodical: periodical | ||
phdthesis: thesis | ||
proceedings: paper-conference | ||
report: report | ||
techreport: report | ||
thesis: thesis | ||
unpublished: manuscript | ||
default_value: article-journal | ||
title: title | ||
field_az_publication_date_type: datetype | ||
field_az_publication_date: | ||
plugin: format_date | ||
from_format: 'Y-m-d' | ||
to_format: 'Y-m-d' | ||
from_timezone: 'UTC' | ||
source: date | ||
field_az_publication_container: | ||
plugin: null_coalesce | ||
source: | ||
- booktitle | ||
- journaltitle | ||
- journal | ||
field_az_publication_abstract/value: | ||
plugin: null_coalesce | ||
source: | ||
- abstract | ||
- annotation | ||
field_az_publication_abstract/format: | ||
plugin: default_value | ||
default_value: az_standard | ||
field_az_publication_location: location | ||
field_az_publication_publisher: | ||
plugin: null_coalesce | ||
source: | ||
- publisher | ||
- institution | ||
- school | ||
field_az_publication_page: pages | ||
'field_az_publication_link/uri': url | ||
field_az_publication_doi: doi | ||
field_az_publication_volume: volume | ||
field_az_publication_issue: number | ||
field_az_publication_version: version | ||
field_az_authors: | ||
plugin: sub_process | ||
source: author | ||
process: | ||
fullname: | ||
- | ||
plugin: callback | ||
callable: array_filter | ||
source: | ||
- first | ||
- von | ||
- last | ||
- jr | ||
- | ||
plugin: concat | ||
delimiter: ' ' | ||
target_id: | ||
plugin: entity_generate | ||
source: '@fullname' | ||
value_key: name | ||
ignore_case: true | ||
bundle: 1 | ||
bundle_key: status | ||
entity_type: az_author | ||
values: | ||
field_az_author_fname: first | ||
field_az_author_nondrop_particle: von | ||
field_az_author_lname: last | ||
field_az_author_suffix: jr | ||
|
||
destination: | ||
plugin: entity:node | ||
bundle: az_publication | ||
|
||
dependencies: | ||
enforced: | ||
module: | ||
- az_publication |
112 changes: 112 additions & 0 deletions
112
modules/custom/az_publication/az_publication_bibtex/src/Form/AZPublicationBibtexForm.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace Drupal\az_publication_bibtex\Form; | ||
|
||
use Drupal\Core\Form\FormBase; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Drupal\file\Entity\File; | ||
use Drupal\migrate\Plugin\MigrationInterface; | ||
use Drupal\migrate_tools\MigrateBatchExecutable; | ||
use Drupal\migrate\MigrateMessage; | ||
|
||
/** | ||
* BibTeX import form. | ||
*/ | ||
class AZPublicationBibtexForm extends FormBase { | ||
|
||
/** | ||
* The migration plugin manager. | ||
* | ||
* @var \Drupal\migrate\Plugin\MigrationPluginManager | ||
*/ | ||
protected $pluginManagerMigration; | ||
|
||
/** | ||
* @var \Drupal\Core\File\FileSystemInterface | ||
*/ | ||
protected $fileSystem; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
$instance = parent::create($container); | ||
$instance->fileSystem = $container->get('file_system'); | ||
$instance->pluginManagerMigration = $container->get('plugin.manager.migration'); | ||
return $instance; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFormId() { | ||
return 'az_publication_bibtex_import_form'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(array $form, FormStateInterface $form_state) { | ||
|
||
$form['bibtex'] = [ | ||
'#type' => 'managed_file', | ||
'#title' => $this->t('Upload a BibTeX document'), | ||
'#upload_location' => 'temporary://bibtex/', | ||
'#upload_validators' => [ | ||
'file_validate_extensions' => ['bib'], | ||
], | ||
'#required' => TRUE, | ||
]; | ||
$form['submit'] = [ | ||
'#type' => 'submit', | ||
'#value' => $this->t('Import'), | ||
]; | ||
|
||
return $form; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function validateForm(array &$form, FormStateInterface $form_state) { | ||
|
||
parent::validateForm($form, $form_state); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function submitForm(array &$form, FormStateInterface $form_state) { | ||
$values = $form_state->getValues(); | ||
if (!empty($values['bibtex'])) { | ||
$fid = reset($values['bibtex']); | ||
$file = File::load($fid); | ||
if (!empty($file)) { | ||
$uri = $file->getFileUri(); | ||
$path = $this->fileSystem->realpath($uri); | ||
$migration_id = 'az_publication_bibtex_import'; | ||
/** @var \Drupal\migrate\Plugin\Migration $migration */ | ||
$migration = $this->pluginManagerMigration->createInstance($migration_id); | ||
// Reset status. | ||
$status = $migration->getStatus(); | ||
if ($status !== MigrationInterface::STATUS_IDLE) { | ||
$migration->setStatus(MigrationInterface::STATUS_IDLE); | ||
} | ||
$options = [ | ||
'limit' => 0, | ||
'update' => 1, | ||
'force' => 0, | ||
'configuration' => [ | ||
'source' => [ | ||
'urls' => $path, | ||
], | ||
], | ||
]; | ||
$executable = new MigrateBatchExecutable($migration, new MigrateMessage(), $options); | ||
$executable->batchImport(); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.