Skip to content

Commit

Permalink
Address #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Jul 30, 2016
1 parent 442cc92 commit 5736d29
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ An Islandora Solution Pack that allows for ingesting and viewing arbitrary types

This solution pack provides well-understood tools for ingesting and viewing XML OBJ files in Islandora. These files could be TEI, EAD, DocBook, SVG, or locally defined XML. It is simpler than Islandora Feeds because:

* It does not offer any way of editing the XML files. If users need to modify an XML file, they must replace the object's OBJ datastream using the standard tools provided within an object's Datastreams tab, just like with any other solution pack's OBJ datastream.
* It offers only a very rudimentary way of editing an XML file - just a plain text area. If users need to modify an XML file using more sophisticated tools, they must edit the object's OBJ XML datastream outside of Islandora and replace the datastream using the "Replace" provided within the object's Datastreams tab.
* It does not generate any derivatives. However, the 'modules' subdirectory contains an example module that illustrates how you would generate derivatives.

Users may upload a thumbnail image and default XSLT stylesheet for each XML object. Objects managed by this solution pack can also have a MODS datastream just like other Islandora objects do.
Expand Down
62 changes: 62 additions & 0 deletions includes/xml_object_edit.form.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* @file
* XML OBJ editing form.
*/

/**
* Retrives the XML edit form.
*
* @param AbstractObject $object
* The Islandora object.
*
* @return array
* The form array.
*/
function islandora_solution_pack_xml_edit_xml(AbstractObject $object) {
return drupal_get_form('islandora_solution_pack_xml_edit_xml_form', $object);
}

/**
* Form callback.
*/
function islandora_solution_pack_xml_edit_xml_form($form, &$form_state, AbstractObject $object) {
$xml = $object['OBJ']->content;
return array(
'xml' => array(
'#title' => t('XML OBJ datastream content'),
'#type' => 'textarea',
'#rows' => 20,
'#description' => t('Edit your XML here. Note that no validation or well-formedness checking is performed on this content.'),
'#default_value' => $xml,
),
'object' => array(
'#type' => 'value',
'#value' => $object->id,
),
'submit' => array(
'#type' => 'submit',
'#value' => t('Save'),
),
);
}

/**
* From submit function.
*/
function islandora_solution_pack_xml_edit_xml_form_submit($form, &$form_state) {
$object = islandora_object_load($form_state['values']['object']);
if (!$object['OBJ']) {
$xml = $object->constructDatastream('OBJ', 'M');
$xml->mimetype = 'application/xml';
$xml->label = 'XML content';
}
else {
$xml = $object['OBJ'];
}
$xml->setContentFromString($form_state['values']['xml']);
$object->ingestDatastream($xml);
drupal_set_message(t("XML updated for !object.", array('!object' => $object->id)));
drupal_goto("islandora/object/{$object->id}/manage/datastreams");
}
24 changes: 24 additions & 0 deletions islandora_solution_pack_xml.module
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,33 @@ function islandora_solution_pack_xml_menu() {
'file' => 'includes/admin.form.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['islandora/object/%islandora_object/datastreams/OBJ/edit'] = array(
'title' => 'Edit XML file',
'file' => 'includes/xml_object_edit.form.inc',
'page callback' => 'islandora_solution_pack_xml_edit_xml',
'page arguments' => array(2),
'access callback' => 'islandora_object_manage_access_callback',
'access arguments' => array(2),
'type' => MENU_CALLBACK,
);
return $items;
}

/**
* Implements hook_islandora_edit_datastream_registry().
*/
function islandora_solution_pack_xml_islandora_edit_datastream_registry($object, $dsid) {
if (in_array('islandora:sp_simple_xml', $object->models) &&
$dsid->id == 'OBJ') {
return array(
array(
'name' => t('XML Edit form'),
'url' => "islandora/object/{$object->id}/datastreams/OBJ/edit",
),
);
}
}

/**
* Implements hook_theme().
*
Expand Down

0 comments on commit 5736d29

Please sign in to comment.