diff --git a/islandora/include/fields.inc b/islandora/include/fields.inc index 6e3382dc..61e32a49 100644 --- a/islandora/include/fields.inc +++ b/islandora/include/fields.inc @@ -12,10 +12,6 @@ * The name of the bundle to give the fields. */ function islandora_add_fields_to_bundle($bundle_name) { - // If this gets called from an install hook, we can't guarantee the t's - // existance. - $t = get_t(); - // Big list of field names/labels/descriptions. $field_data = array( ISLANDORA_TN_FIELD => array( @@ -42,22 +38,58 @@ function islandora_add_fields_to_bundle($bundle_name) { $field_label = $data['label']; $field_description = $data['description']; - if (field_info_field($field_name)) { - $field_instance = array( - 'field_name' => $field_name, - 'entity_type' => 'node', - 'bundle' => $bundle_name, - 'label' => $t("@label", array("@label" => $field_label)), - 'description' => $t("@description", array("@description" => $field_description)), - 'required' => FALSE, - ); - field_create_instance($field_instance); - $message = $t('Field @name was added to @bundle successfully', - array( - '@name' => $field_name, - '@bundle' => $bundle_name, - )); - drupal_set_message($message); - } + islandora_add_field_to_bundle($bundle_name, $field_name, $field_label, $field_description); + } +} + +/** + * Adds a field to a bundle. + * + * @param string $bundle_name + * The machine name of the bundle. + * @param string $field_name + * The machine name of the field. + * @param string $field_label + * The human-readable label for the field. + * @param string $field_description + * The human-readable description for the field. + */ +function islandora_add_field_to_bundle($bundle_name, $field_name, $field_label, $field_description) { + // If this gets called from an install hook, we can't guarantee the t's + // existance. + $t = get_t(); + + if (field_info_field($field_name)) { + $field_instance = array( + 'field_name' => $field_name, + 'entity_type' => 'node', + 'bundle' => $bundle_name, + 'label' => $t("@label", array("@label" => $field_label)), + 'description' => $t("@description", array("@description" => $field_description)), + 'required' => FALSE, + ); + field_create_instance($field_instance); + $message = $t('Field @name was added to @bundle successfully', + array( + '@name' => $field_name, + '@bundle' => $bundle_name, + )); + drupal_set_message($message); } } + +/** + * Creates a field from a field definition. + * + * @param array $field_definition + * Field definition for the desired field. + */ +function islandora_create_field($field_definition) { + // If this gets called from an install hook, we can't guarantee the t's + // existance. + $t = get_t(); + + field_create_field($field_definition); + drupal_set_message($t("Created field @field", + array("@field" => $field_definition['field_name']))); +} diff --git a/islandora/include/rdf_mapping.inc b/islandora/include/rdf_mapping.inc index ed50d13d..65cdf96a 100644 --- a/islandora/include/rdf_mapping.inc +++ b/islandora/include/rdf_mapping.inc @@ -16,16 +16,16 @@ * @return array * The default RDF mapping for Islandora content types. */ -function islandora_get_default_rdf_mapping($bundle, $rdf_type) { +function islandora_get_default_rdf_mapping($bundle, $rdf_types) { return array( array( 'type' => 'node', 'bundle' => $bundle, 'mapping' => array( - 'rdftype' => array($rdf_type), + 'rdftype' => $rdf_types, 'uuid' => array( - 'predicates' => array('dc11:identifier'), - 'datatype' => 'xsd:ID', + 'predicates' => array('fedora:uuid'), + 'datatype' => 'xsd:string', ), ISLANDORA_FEDORA_HAS_PARENT_FIELD => array( 'predicates' => array('fedora:hasParent'), @@ -35,66 +35,6 @@ function islandora_get_default_rdf_mapping($bundle, $rdf_type) { 'predicates' => array('pcdm:hasMember'), 'datatype' => 'xsd:string', ), - ISLANDORA_DC_CONTRIBUTOR_FIELD => array( - 'predicates' => array('dc11:contributor'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_COVERAGE_FIELD => array( - 'predicates' => array('dc11:coverage'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_CREATOR_FIELD => array( - 'predicates' => array('dc11:creator'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_DATE_FIELD => array( - 'predicates' => array('dc11:date'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_DESCRIPTION_FIELD => array( - 'predicates' => array('dc11:description'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_FORMAT_FIELD => array( - 'predicates' => array('dc11:format'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_IDENTIFIER_FIELD => array( - 'predicates' => array('dc11:identifier'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_LANGUAGE_FIELD => array( - 'predicates' => array('dc11:language'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_PUBLISHER_FIELD => array( - 'predicates' => array('dc11:publisher'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_RELATION_FIELD => array( - 'predicates' => array('dc11:relation'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_RIGHTS_FIELD => array( - 'predicates' => array('dc11:rights'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_SOURCE_FIELD => array( - 'predicates' => array('dc11:source'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_SUBJECT_FIELD => array( - 'predicates' => array('dc11:subject'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_TITLE_FIELD => array( - 'predicates' => array('dc11:title'), - 'datatype' => 'xsd:string', - ), - ISLANDORA_DC_TYPE_FIELD => array( - 'predicates' => array('dc11:type'), - 'datatype' => 'xsd:string', - ), ), ), ); diff --git a/islandora/islandora.install b/islandora/islandora.install index 5d560636..6ee21f11 100644 --- a/islandora/islandora.install +++ b/islandora/islandora.install @@ -11,37 +11,28 @@ * Defines common fields for various bundles. */ function islandora_install() { - $t = get_t(); + module_load_include('inc', 'islandora', 'include/fields'); - $tn_field = array( - 'field_name' => ISLANDORA_TN_FIELD, - 'type' => 'image', + $fields = array( + array( + 'field_name' => ISLANDORA_TN_FIELD, + 'type' => 'image', + ), + array( + 'field_name' => ISLANDORA_FEDORA_PATH_FIELD, + 'type' => 'text', + ), + array( + 'field_name' => ISLANDORA_FEDORA_HAS_PARENT_FIELD, + 'type' => 'text', + ), + array( + 'field_name' => ISLANDORA_PCDM_HAS_MEMBER_FIELD, + 'type' => 'text', + ), ); - field_create_field($tn_field); - drupal_set_message($t("Created field @field", - array("@field" => ISLANDORA_TN_FIELD))); - $fedora_path_field = array( - 'field_name' => ISLANDORA_FEDORA_PATH_FIELD, - 'type' => 'text', - ); - field_create_field($fedora_path_field); - drupal_set_message($t("Created field @field", - array("@field" => ISLANDORA_FEDORA_PATH_FIELD))); - - $fedora_has_parent_field = array( - 'field_name' => ISLANDORA_FEDORA_HAS_PARENT_FIELD, - 'type' => 'text', - ); - field_create_field($fedora_has_parent_field); - drupal_set_message($t("Created field @field", - array("@field" => ISLANDORA_FEDORA_HAS_PARENT_FIELD))); - - $pcdm_has_member_field = array( - 'field_name' => ISLANDORA_PCDM_HAS_MEMBER_FIELD, - 'type' => 'text', - ); - field_create_field($pcdm_has_member_field); - drupal_set_message($t("Created field @field", - array("@field" => ISLANDORA_PCDM_HAS_MEMBER_FIELD))); + foreach ($fields as $field) { + islandora_create_field($field); + } } diff --git a/islandora/islandora.module b/islandora/islandora.module index 7a10c315..7dabf9c1 100644 --- a/islandora/islandora.module +++ b/islandora/islandora.module @@ -6,8 +6,13 @@ */ define('ISLANDORA_NAMESPACE', 'http://islandora.ca/ontology/v2/'); +define('ISLANDORA_NAMESPACE_PREFIX', 'islandora'); define('ISLANDORA_FEDORA_NAMESPACE', 'http://fedora.info/definitions/v4/repository#'); +define('ISLANDORA_FEDORA_NAMESPACE_PREFIX', 'fedora'); define('ISLANDORA_PCDM_NAMESPACE', 'http://pcdm.org/models#'); +define('ISLANDORA_PCDM_NAMESPACE_PREFIX', 'pcdm'); +define('ISLANDORA_NFO_NAMESPACE', 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.2/'); +define('ISLANDORA_NFO_NAMESPACE_PREFIX', 'nfo'); define('ISLANDORA_TN_FIELD', 'field_tn'); define('ISLANDORA_FEDORA_PATH_FIELD', 'field_fedora_path'); define('ISLANDORA_FEDORA_HAS_PARENT_FIELD', 'field_fedora_has_parent'); @@ -29,9 +34,10 @@ function islandora_ctools_plugin_api($owner, $api) { */ function islandora_rdf_namespaces() { return array( - 'islandora' => ISLANDORA_NAMESPACE, - 'fedora' => ISLANDORA_FEDORA_NAMESPACE, - 'pcdm' => ISLANDORA_PCDM_NAMESPACE, + ISLANDORA_NAMESPACE_PREFIX => ISLANDORA_NAMESPACE, + ISLANDORA_FEDORA_NAMESPACE_PREFIX => ISLANDORA_FEDORA_NAMESPACE, + ISLANDORA_PCDM_NAMESPACE_PREFIX => ISLANDORA_PCDM_NAMESPACE, + ISLANDORA_NFO_NAMESPACE_PREFIX => ISLANDORA_NFO_NAMESPACE, ); } diff --git a/islandora_basic_image/islandora_basic_image.install b/islandora_basic_image/islandora_basic_image.install index c87589f9..2e716268 100644 --- a/islandora_basic_image/islandora_basic_image.install +++ b/islandora_basic_image/islandora_basic_image.install @@ -14,34 +14,14 @@ function islandora_basic_image_install() { // Ensure the basic image node type is available. node_types_rebuild(); - $t = get_t(); - - // Create medium size field. - $medium_size_field = array( - 'field_name' => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD, - 'type' => 'image', - ); - field_create_field($medium_size_field); - drupal_set_message($t("Created field @field", - array("@field" => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD))); + // Add default islandora fields. + islandora_add_fields_to_bundle(ISLANDORA_BASIC_IMAGE_CONTENT_TYPE); - // Add fields instances to bundle. - if (field_info_field(ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD)) { - $medium_size_field_instance = array( - 'field_name' => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD, - 'entity_type' => 'node', - 'bundle' => ISLANDORA_BASIC_IMAGE_CONTENT_TYPE, - 'label' => $t("Medium Size"), - 'description' => $t("A display copy of the image."), - 'required' => FALSE, - ); - field_create_instance($medium_size_field_instance); - drupal_set_message($t('Field @name was successfully added to @bundle', - array( - '@name' => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD, - '@bundle' => ISLANDORA_BASIC_IMAGE_CONTENT_TYPE, - ))); - } + // Create medium size field and add to bundle. + islandora_create_field(array( + 'field_name' => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD, + 'type' => 'image', + )); + islandora_add_field_to_bundle(ISLANDORA_BASIC_IMAGE_CONTENT_TYPE, ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD, "Medium Size", "A display copy of the image"); - islandora_add_fields_to_bundle(ISLANDORA_BASIC_IMAGE_CONTENT_TYPE); } diff --git a/islandora_collection/islandora_collection.info b/islandora_collection/islandora_collection.info index b689010d..a2a6503a 100644 --- a/islandora_collection/islandora_collection.info +++ b/islandora_collection/islandora_collection.info @@ -4,3 +4,4 @@ package = Islandora version = 7.x-dev core = 7.x dependencies[] = islandora +dependencies[] = hook_post_action diff --git a/islandora_collection/islandora_collection.install b/islandora_collection/islandora_collection.install index 995b1437..7f5791ca 100644 --- a/islandora_collection/islandora_collection.install +++ b/islandora_collection/islandora_collection.install @@ -17,7 +17,4 @@ function islandora_collection_install() { // Add default Islandora fields. islandora_add_fields_to_bundle(ISLANDORA_COLLECTION_CONTENT_TYPE); - - // Create the pcdm:hasMember relation. - islandora_collection_define_relations(); } diff --git a/islandora_collection/islandora_collection.module b/islandora_collection/islandora_collection.module index 8106e633..33153cef 100644 --- a/islandora_collection/islandora_collection.module +++ b/islandora_collection/islandora_collection.module @@ -47,15 +47,35 @@ function islandora_collection_rdf_mapping() { } /** - * Implements hook_insert(). + * Implements hook_node_postinsert(). */ -function islandora_collection_insert($node) { +function islandora_collection_node_postinsert($node) { + // Exit early if it's not a collection. + if (strcmp($node->type, ISLANDORA_COLLECTION_CONTENT_TYPE) != 0) { + return; + } + $nodes = entity_uuid_load('node', array($node->uuid)); + + // Exit early if the node never was successfully inserted in the database. + if (empty($nodes)) { + return; + } + + $node = array_pop($nodes); + $response = drupal_http_request("http://localhost:8080/islandora-services/rest/collection", + array( + 'method' => 'POST', + 'data' => json_encode($node), + )); + + dd("RESPONSE"); + dd($response->data); } /** * Implements hook_update(). */ -function islandora_collection_update($node) { - +function islandora_collection_node_postupdate($node) { + dd("FROM POST UPDATE HOOK"); } diff --git a/islandora_dc/include/fields.inc b/islandora_dc/include/fields.inc index 13c970e5..8e7e6d74 100644 --- a/islandora_dc/include/fields.inc +++ b/islandora_dc/include/fields.inc @@ -12,10 +12,7 @@ * The name of the bundle to give the fields. */ function islandora_dc_add_fields_to_bundle($bundle_name) { - - // If this gets called from an install hook, we can't guarantee the t's - // existance. - $t = get_t(); + module_load_include('inc', 'islandora', 'include/fields'); // Big list of field names/labels/descriptions. $field_data = array( @@ -86,22 +83,6 @@ function islandora_dc_add_fields_to_bundle($bundle_name) { $field_label = $data['label']; $field_description = $data['description']; - if (field_info_field($field_name)) { - $field_instance = array( - 'field_name' => $field_name, - 'entity_type' => 'node', - 'bundle' => $bundle_name, - 'label' => $t("@label", array("@description" => $field_label)), - 'description' => $t("@description", array("@description" => $field_description)), - 'required' => FALSE, - ); - field_create_instance($field_instance); - $message = $t('Field @name was successfully added to @bundle', - array( - '@name' => $field_name, - '@bundle' => $bundle_name, - )); - drupal_set_message($message); - } + islandora_add_field_to_bundle($bundle_name, $field_name, $field_label, $field_description); } } diff --git a/islandora_dc/islandora_dc.install b/islandora_dc/islandora_dc.install index b751821c..e286f2de 100644 --- a/islandora_dc/islandora_dc.install +++ b/islandora_dc/islandora_dc.install @@ -11,7 +11,7 @@ * Creates shared fields for content types using DC metadata. */ function islandora_dc_install() { - $t = get_t(); + module_load_include('inc', 'islandora', 'include/fields'); $field_names = array( ISLANDORA_DC_CONTRIBUTOR_FIELD, @@ -32,13 +32,11 @@ function islandora_dc_install() { ); foreach ($field_names as $field_name) { - $field = array( - 'field_name' => $field_name, - 'type' => 'text_long', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, - ); - field_create_field($field); - drupal_set_message($t("Created field @field", - array("@field" => $field_name))); + islandora_create_field(array( + 'field_name' => $field_name, + 'type' => 'text_long', + 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + )); } + } diff --git a/islandora_mods/include/fields.inc b/islandora_mods/include/fields.inc index eb63f11c..0aa45496 100644 --- a/islandora_mods/include/fields.inc +++ b/islandora_mods/include/fields.inc @@ -12,25 +12,6 @@ * The name of the bundle to give the fields. */ function islandora_mods_add_fields_to_bundle($bundle_name) { - // If this gets called from an install hook, we can't guarantee the t's - // existance. - $t = get_t(); - - if (field_info_field(ISLANDORA_MODS_FIELD)) { - $mods_field_instance = array( - 'field_name' => ISLANDORA_MODS_FIELD, - 'entity_type' => 'node', - 'bundle' => $bundle_name, - 'label' => $t("MODS XML"), - 'description' => $t("A MODS record for the Fedora resource"), - 'required' => FALSE, - ); - field_create_instance($mods_field_instance); - $message = $t('Field @name was successfully added to @bundle', - array( - '@name' => ISLANDORA_MODS_FIELD, - '@bundle' => $bundle_name, - )); - drupal_set_message($message); - } + module_load_include('inc', 'islandora', 'include/fields'); + islandora_add_field_to_bundle($bundle_name, ISLANDORA_MODS_FIELD, "MODS XML", "A MODS record for the Fedora resource"); } diff --git a/islandora_mods/islandora_mods.install b/islandora_mods/islandora_mods.install index 0419f373..ca5f6a86 100644 --- a/islandora_mods/islandora_mods.install +++ b/islandora_mods/islandora_mods.install @@ -11,13 +11,10 @@ * Creates shared fields for content types using MODS metadata. */ function islandora_mods_install() { - $t = get_t(); + module_load_include('inc', 'islandora', 'include/fields'); - $mods_field = array( - 'field_name' => ISLANDORA_MODS_FIELD, - 'type' => 'xml_field_xml', - ); - field_create_field($mods_field); - drupal_set_message($t("Created field @field", - array("@field" => ISLANDORA_MODS_FIELD))); + islandora_create_field(array( + 'field_name' => ISLANDORA_MODS_FIELD, + 'type' => 'xml_field_xml', + )); }