diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index 47a8f23c..e4cb23bd 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -58,6 +58,46 @@ function islandora_solution_packs_get_required_objects($module = NULL) { } } +/** + * Convenience function used to create objects in hook_required_objects(). + * + * @param IslandoraTuque $connection + * The connection to the fedora repository. + * @param array $args + * An associative array defining the objects properties and datastreams" + * - pid: The identifier for the new object. + * - label: The new object's label. + * - models: String / array of content model identifier(s) for the new object. + * - datastreams: An associative array of properties for each datastream where + * each key represents the datastream's identifier: + * - control_group: The control group for this datastream defaults to 'M'. + * - label: The datastream's label. + * - file: The file path to the datastream's content. + * - mimetype: The mimetype of the given file. Defaults to 'text/xml'. + * + * @return AbstractObject + * A new Fedora Object, that has yet to be persisted to the repository. + */ +function islandora_solution_pack_create_required_object(IslandoraTuque $connection, array $args) { + $object = $connection->repository->constructObject($args['pid']); + $object->owner = 'fedoraAdmin'; + $object->label = $args['label']; + foreach ($args['datastreams'] as $dsid => $properties) { + $control_group = isset($properties['control_group']) ? $properties['control_group'] : 'M'; + $datastream = $object->constructDatastream($dsid, $control_group); + $datastream->label = isset($properties['label']) ? $properties['label'] : $dsid; + $datastream->mimetype = isset($properties['mimetype']) ? $properties['mimetype'] : 'text/xml'; + $datastream->setContentFromFile($properties['file'], FALSE); + $object->ingestDatastream($datastream); + } + // We must set the model after the datastreams as Tuque will ignore the + // RELS-EXT content if the model is set first. + if (isset($args['model'])) { + $object->models = $args['model']; + } + return $object; +} + /** * Solution pack admin page callback. *