bibcite-8.x-1.x-dev/modules/bibcite_endnote/bibcite_endnote.install
modules/bibcite_endnote/bibcite_endnote.install
<?php
/**
* @file
* Module installation hooks implementation.
*/
/**
* Fix Endnote 7 XML format mapping for secondary-title, short-title and translated-title fields.
*/
function bibcite_endnote_update_8001() {
$config = \Drupal::configFactory()->getEditable('bibcite_entity.mapping.endnote8');
$fields = $config->get('fields');
// Set mapping for secondary-title field basing on incorrect title-secondary
// field mapping.
$fields['secondary-title'] = (isset($fields['title-secondary']))
? $fields['title-secondary']
: '';
unset($fields['title-secondary']);
// Config installed with the module is shipped with correct mapping i.e. it
// sets short-title field mapping. Existing in config title-short field means
// that config was updated using settings form.
if (isset($fields['title-short'])) {
// If title-short mapping was intentionally set to some field, then let's
// use this mapping to restore short-title mapping.
if ($fields['title-short'] !== '') {
$fields['short-title'] = $fields['title-short'];
}
// Otherwise let's set to default mapping.
else {
$fields['short-title'] = 'bibcite_short_title';
}
unset($fields['title-short']);
}
// Fix translated-title mapping if default mapping is used which maps to
// non-existing bibcite_translated-title field.
if (isset($fields['translated-title']) && $fields['translated-title'] === 'bibcite_translated-title') {
$fields['translated-title'] = 'bibcite_translated_title';
}
// Save config updates.
$config->set('fields', $fields);
$config->save(TRUE);
}
/**
* Add new issue and edition fields to the EndNote X3 XML format mapping.
*/
function bibcite_endnote_update_8002() {
$config = \Drupal::configFactory()->getEditable('bibcite_entity.mapping.endnote8');
$fields = $config->get('fields');
$fields['issue'] = 'bibcite_issue';
$fields['edition'] = 'bibcite_edition';
$config->set('fields', $fields);
$config->save(TRUE);
}
/**
* Implements hook_uninstall().
*/
function bibcite_endnote_uninstall() {
Drupal::configFactory()->getEditable('bibcite_entity.mapping.endnote7')->delete();
Drupal::configFactory()->getEditable('bibcite_entity.mapping.endnote8')->delete();
Drupal::configFactory()->getEditable('bibcite_entity.mapping.tagged')->delete();
}
