Browse Source

Alter term creation out to a migration.

... also, identify the term by URI instead of by name, as it's the URI
that is used to related to it from config.
pull/907/head
Adam Vessey 3 years ago
parent
commit
59bc5998cf
No known key found for this signature in database
GPG Key ID: 89B39535BF6D0D39
  1. 60
      islandora_fits.install
  2. 25
      migrations/islandora_fits_tags.yml

60
islandora_fits.install

@ -6,25 +6,22 @@
*/
use Drupal\taxonomy\Entity\Term;
use Drupal\field\Entity\FieldConfig;
/**
* Implements hook_install().
*/
function islandora_fits_install() {
$term_name = 'FITS File';
$test_terms = taxonomy_term_load_multiple_by_name($term_name);
if (!$test_terms) {
$term = Term::create([
'parent' => [],
'name' => $term_name,
'vid' => 'islandora_media_use',
'description' => 'Technical Metadata associated with an original media file',
'field_external_uri' => ['uri' => 'https://projects.iq.harvard.edu/fits'],
])->save();
function islandora_fits_install($is_syncing) {
if (!_islandora_fits_term_exists()) {
$callable = $is_syncing ? [\Drupal::messenger(), 'addStatus'] : [\Drupal::messenger(), 'addWarning'];
$callable(t('A term in the taxonomy @vid with the URI @uri does not appear to exist. The @migration_id migration can be executed to create it.', [
'@vid' => 'islandora_media_use',
'@uri' => 'https://projects.iq.harvard.edu/fits',
'@migration_id' => 'islandora_fits_tags',
]));
}
// Add xml extension if it doesn't already exist.
$field = FieldConfig::load("media.file.field_media_file");
if ($field) {
@ -37,3 +34,40 @@ function islandora_fits_install() {
}
}
}
/**
* Implements hook_requirements().
*/
function islandora_fits_requirements($phase) : array {
$requirements = [];
if ($phase == 'runtime') {
$term_exists = _islandora_fits_term_exists();
$requirements['islandora_fits_term_exists'] = [
'title' => t('FITS Term Exists'),
'value' => $term_exists,
'description' => t('Whether or not a term with the URI targeted by default FITS derivative configuration exists. If derivative configurations were made to target another URI, this can probably be ignored.'),
'severity' => $term_exists ? REQUIREMENT_OK : REQUIREMENT_WARNING
];
}
return $requirements;
}
/**
* Helper; determine if a term with the target URI exists.
*
* @return bool
* TRUE if a term (at least one) with the target URI exists; otherwise, FALSE.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
function _islandora_fits_term_exists() {
$query = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->getQuery()
->condition('vid', 'islandora_media_use')
->condition('field_external_uri.uri', 'https://projects.iq.harvard.edu/fits')
->count();
$count = $query->execute();
return $count > 0;
}

25
migrations/islandora_fits_tags.yml

@ -0,0 +1,25 @@
---
id: islandora_fits_tags
migration_tags:
- islandora
migration_group: islandora
label: "FITS Term(s)"
source:
plugin: embeddedd_data
data_rows:
- vid: islandora_media_use
name: FITS File
description: Technical Metadata associated with an original media file
uri: https://projects.iq.harvard.edu/fits
ids:
uri:
type: string
process:
vid: vid
name: name
description: description
field_external_uri/uri: uri
destination:
plugin: entity:taxonomy_term
migration_dependencies:
required: { }
Loading…
Cancel
Save