Skip to content

Instantly share code, notes, and snippets.

@btmash
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btmash/61cbe892536e9f9e5c67 to your computer and use it in GitHub Desktop.
Save btmash/61cbe892536e9f9e5c67 to your computer and use it in GitHub Desktop.
Create custom forms.
diff --git a/includes/admin.form.inc b/includes/admin.form.inc
new file mode 100644
index 0000000..8970475
--- /dev/null
+++ b/includes/admin.form.inc
@@ -0,0 +1,26 @@
+<?php
+
+function islandora_marcxml_settings($form, &$form_state) {
+ $form['islandora_marcxml_mods_to_marc_xsl_path'] = array(
+ '#type' => 'textfield',
+ '#title' => t('MODS to MARCXML XSL Path'),
+ '#description' => t('Please enter the xsl file path to convert from MODS to MARCXML'),
+ '#default_value' => variable_get('islandora_marcxml_mods_to_marc_xsl_path', drupal_get_path('module', 'islandora_marcxml') . '/xsl/MODS2MARC21slim.xsl'),
+ '#required' => TRUE,
+ );
+
+ $form['islandora_marcxml_marc_to_html_xsl_path'] = array(
+ '#type' => 'textfield',
+ '#title' => t('MARCXML to HTML XSL Path'),
+ '#description' => t('Please enter the xsl file path to convert from MODS to MARCXML'),
+ '#default_value' => variable_get('islandora_marcxml_marc_to_html_xsl_path', drupal_get_path('module', 'islandora_marcxml') . '/xsl/MARC21slim2HTML.xsl'),
+ '#required' => TRUE,
+ );
+
+ $form['islandora_marcxml_marc_to_mods_xsl_path'] = array(
+ '#type' => 'textfield',
+ '#title' => t('MODS to MARCXML XSL Path'),
+ '#description' => t('Please enter the xsl file path to convert from MODS to MARCXML'),
+ '#default_value' => variable_get('islandora_marcxml_marc_to_mods_xsl_path', drupal_get_path('module', 'islandora_marcxml') . '/xsl/MARC21slim2MODS3-5.xsl'),
+ '#required' => TRUE,
+ );
+
+ return system_settings_form($form);
+}
\ No newline at end of file
diff --git a/includes/utilities.inc b/includes/utilities.inc
index 51e4d5e..5dbe64d 100644
--- a/includes/utilities.inc
+++ b/includes/utilities.inc
@@ -43,7 +43,7 @@ function islandora_marcxml_transform_mods_to_marcxml(AbstractObject $object) {
$mods_str = trim($object['MODS']->content);
return islandora_marcxml_run_xsl_transform(array(
'input' => $mods_str,
- 'xsl' => drupal_get_path('module', 'islandora_marcxml') . '/xsl/MODS2MARC21slim.xsl',
+ 'xsl' => variable_get('islandora_marcxml_mods_to_marc_xsl_path', drupal_get_path('module', 'islandora_marcxml') . '/xsl/MODS2MARC21slim.xsl'),
));
}
@@ -61,7 +61,7 @@ function islandora_marcxml_transform_mods_to_marcxml(AbstractObject $object) {
function islandora_marcxml_transform_marc_to_html(AbstractObject $object) {
return islandora_marcxml_run_xsl_transform(array(
'input' => islandora_marcxml_transform_mods_to_marcxml($object),
- 'xsl' => drupal_get_path('module', 'islandora_marcxml') . '/xsl/MARC21slim2HTML.xsl',
+ 'xsl' => variable_get('islandora_marcxml_marc_to_html_xsl_path', drupal_get_path('module', 'islandora_marcxml') . '/xsl/MARC21slim2HTML.xsl'),
));
}
@@ -79,7 +79,7 @@ function islandora_marcxml_transform_marc_to_html(AbstractObject $object) {
function islandora_marcxml_populate_mods(AbstractObject $object, $file) {
$created = FALSE;
$transform_args = array(
- 'xsl' => drupal_get_path('module', 'islandora_marcxml') . '/xsl/MARC21slim2MODS3-5.xsl',
+ 'xsl' => variable_get('islandora_marcxml_marc_to_mods_xsl_path', drupal_get_path('module', 'islandora_marcxml') . '/xsl/MARC21slim2MODS3-5.xsl'),
'input' => file_get_contents($file->uri),
);
$transformed_xml = trim(islandora_marcxml_run_xsl_transform($transform_args));
diff --git a/islandora_marcxml.install b/islandora_marcxml.install
new file mode 100644
index 0000000..bfc70f9
--- /dev/null
+++ b/islandora_marcxml.install
@@ -0,0 +1,11 @@
+<?php
+
+/**
+ * Implements hook_install().
+ */
+function islandora_marcxml_install() {
+ $islandora_marcxml_path = drupal_get_path('module', 'islandora_marcxml');
+ variable_set('islandora_marcxml_mods_to_marc_xsl_path', $islandora_marcxml_path . '/xsl/MODS2MARC21slim.xsl');
+ variable_set('islandora_marcxml_marc_to_html_xsl_path', $islandora_marcxml_path . '/xsl/MARC21slim2HTML.xsl');
+ variable_set('islandora_marcxml_marc_to_mods_xsl_path', $islandora_marcxml_path . '/xsl/MARC21slim2MODS3-5.xsl');
+}
diff --git a/islandora_marcxml.module b/islandora_marcxml.module
index 083771e..b78858e 100644
--- a/islandora_marcxml.module
+++ b/islandora_marcxml.module
@@ -32,6 +32,14 @@ function islandora_marcxml_menu() {
'delivery callback' => 'islandora_marcxml_xml_download',
'file' => 'includes/utilities.inc',
),
+ 'admin/islandora/islandora_marcxml' => array(
+ 'title' => 'MarcXML configuration',
+ 'type' => MENU_NORMAL_ITEM,
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('islandora_marcxml_settings'),
+ 'access arguments' => array('administer site configuration'),
+ 'file' => 'includes/admin.form.inc',
+ ),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment