You are here

bibcite_endnote.install in Bibliography & Citation 8

Same filename and directory in other branches
  1. 2.0.x modules/bibcite_endnote/bibcite_endnote.install

Module installation hooks implementation.

File

modules/bibcite_endnote/bibcite_endnote.install
View source
<?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'];
    }
    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();
}

Functions

Namesort descending Description
bibcite_endnote_uninstall Implements hook_uninstall().
bibcite_endnote_update_8001 Fix Endnote 7 XML format mapping for secondary-title, short-title and translated-title fields.
bibcite_endnote_update_8002 Add new issue and edition fields to the EndNote X3 XML format mapping.