Browse Source

Reworking how content types are defined so we can use hooks for specific content types.

7.x-2.x
Daniel Lamb 10 years ago
parent
commit
05da4529cf
  1. 36
      islandora_basic_image/islandora_basic_image.install
  2. 23
      islandora_basic_image/islandora_basic_image.module
  3. 37
      islandora_collection/include/fields.inc
  4. 7
      islandora_collection/islandora_collection.install
  5. 16
      islandora_collection/islandora_collection.module

36
islandora_basic_image/islandora_basic_image.install

@ -11,32 +11,10 @@
function islandora_basic_image_install() { function islandora_basic_image_install() {
module_load_include('inc', 'islandora_dcterms', 'include/fields'); module_load_include('inc', 'islandora_dcterms', 'include/fields');
$t = get_t(); // Ensure the basic image node type is available.
node_types_rebuild();
// Create basic_image bundle.
$basic_image_content_type = array(
'type' => ISLANDORA_BASIC_IMAGE_BUNDLE,
'name' => $t('Basic Image'),
'base' => 'node_content',
'description' => $t('An image object in Fedora'),
'custom' => 1,
'modified' => 1,
'locked' => 0,
'disabled' => 0,
);
$basic_image_content_type = node_type_set_defaults($basic_image_content_type);
$status = node_type_save($basic_image_content_type);
$t_args = array('%name' => $basic_image_content_type->name); $t = get_t();
if ($status == SAVED_UPDATED) {
drupal_set_message($t('Updated %name content type.', $t_args));
}
elseif ($status == SAVED_NEW) {
drupal_set_message($t('Created %name content type.', $t_args));
}
// Create medium size field. // Create medium size field.
$medium_size_field = array( $medium_size_field = array(
@ -50,7 +28,7 @@ function islandora_basic_image_install() {
$medium_size_field_instance = array( $medium_size_field_instance = array(
'field_name' => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD, 'field_name' => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD,
'entity_type' => 'node', 'entity_type' => 'node',
'bundle' => ISLANDORA_BASIC_IMAGE_BUNDLE, 'bundle' => ISLANDORA_BASIC_IMAGE_CONTENT_TYPE,
'label' => $t("Medium Size"), 'label' => $t("Medium Size"),
'description' => $t("A display copy of the image."), 'description' => $t("A display copy of the image."),
'required' => FALSE, 'required' => FALSE,
@ -63,7 +41,7 @@ function islandora_basic_image_install() {
$tn_field_instance = array( $tn_field_instance = array(
'field_name' => ISLANDORA_TN_FIELD, 'field_name' => ISLANDORA_TN_FIELD,
'entity_type' => 'node', 'entity_type' => 'node',
'bundle' => ISLANDORA_BASIC_IMAGE_BUNDLE, 'bundle' => ISLANDORA_BASIC_IMAGE_CONTENT_TYPE,
'label' => $t("Thumbnail"), 'label' => $t("Thumbnail"),
'description' => $t("A thumbnail for the Fedora resource"), 'description' => $t("A thumbnail for the Fedora resource"),
'required' => FALSE, 'required' => FALSE,
@ -76,7 +54,7 @@ function islandora_basic_image_install() {
$mods_field_instance = array( $mods_field_instance = array(
'field_name' => ISLANDORA_MODS_FIELD, 'field_name' => ISLANDORA_MODS_FIELD,
'entity_type' => 'node', 'entity_type' => 'node',
'bundle' => ISLANDORA_BASIC_IMAGE_BUNDLE, 'bundle' => ISLANDORA_BASIC_IMAGE_CONTENT_TYPE,
'label' => $t("MODS"), 'label' => $t("MODS"),
'description' => $t("A MODS record for the Fedora resource"), 'description' => $t("A MODS record for the Fedora resource"),
'required' => FALSE, 'required' => FALSE,
@ -85,5 +63,5 @@ function islandora_basic_image_install() {
drupal_set_message($t('Field %name was created successfully', array('%name' => ISLANDORA_MODS_FIELD))); drupal_set_message($t('Field %name was created successfully', array('%name' => ISLANDORA_MODS_FIELD)));
} }
islandora_dcterms_attach_fields_to_bundle(ISLANDORA_BASIC_IMAGE_BUNDLE); islandora_dcterms_attach_fields_to_bundle(ISLANDORA_BASIC_IMAGE_CONTENT_TYPE);
} }

23
islandora_basic_image/islandora_basic_image.module

@ -5,16 +5,25 @@
* This is the new Islandora Basic Image module. * This is the new Islandora Basic Image module.
*/ */
define('ISLANDORA_BASIC_IMAGE_BUNDLE', 'basic_image'); define('ISLANDORA_BASIC_IMAGE_CONTENT_TYPE', 'islandora_basic_image');
define('ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD', 'field_medium_size'); define('ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD', 'field_medium_size');
/** /**
* Function for using a form. * Implements hook_node_info().
* */
* @param string $node function islandora_basic_image_node_info() {
* The Drupal node. return array(
* @param array $form_state ISLANDORA_BASIC_IMAGE_CONTENT_TYPE => array(
* The Drupal form state. 'name' => t("Basic Image"),
'base' => ISLANDORA_BASIC_IMAGE_CONTENT_TYPE,
'description' => t("A Drupal node modeling a basic image pcdm:Object"),
'has_title' => FALSE,
),
);
}
/**
* Implements hook_form().
*/ */
function islandora_basic_image_form($node, array &$form_state) { function islandora_basic_image_form($node, array &$form_state) {
return node_content_form($node, $form_state); return node_content_form($node, $form_state);

37
islandora_collection/include/bundles.inc → islandora_collection/include/fields.inc

@ -2,48 +2,23 @@
/** /**
* @file * @file
* Utility functions for defining collection bundles. * Utility functions for attaching default fields to collections.
*/ */
/** /**
* Defines bundles (content types) for this module. * Attaches default fields for this module's content type.
*/ */
function islandora_collection_define_bundles() { function islandora_collection_attach_default_fields() {
module_load_include('inc', 'islandora_dcterms', 'include/fields'); module_load_include('inc', 'islandora_dcterms', 'include/fields');
$t = get_t(); $t = get_t();
// Create basic_image bundle.
$collection_content_type = array(
'type' => ISLANDORA_COLLECTION_BUNDLE,
'name' => $t('Collection'),
'base' => 'node_content',
'description' => $t('A collection in Fedora'),
'custom' => 1,
'modified' => 1,
'locked' => 0,
'disabled' => 0,
);
$collection_content_type = node_type_set_defaults($collection_content_type);
$status = node_type_save($collection_content_type);
$t_args = array('%name' => $collection_content_type->name);
if ($status == SAVED_UPDATED) {
drupal_set_message($t('Updated %name content type.', $t_args));
}
elseif ($status == SAVED_NEW) {
drupal_set_message($t('Created %name content type.', $t_args));
}
// Add thumbnail field. // Add thumbnail field.
if (field_info_field(ISLANDORA_TN_FIELD)) { if (field_info_field(ISLANDORA_TN_FIELD)) {
$tn_field_instance = array( $tn_field_instance = array(
'field_name' => ISLANDORA_TN_FIELD, 'field_name' => ISLANDORA_TN_FIELD,
'entity_type' => 'node', 'entity_type' => 'node',
'bundle' => ISLANDORA_COLLECTION_BUNDLE, 'bundle' => ISLANDORA_COLLECTION_CONTENT_TYPE,
'label' => $t("Thumbnail"), 'label' => $t("Thumbnail"),
'description' => $t("A thumbnail for the Fedora resource"), 'description' => $t("A thumbnail for the Fedora resource"),
'required' => FALSE, 'required' => FALSE,
@ -57,7 +32,7 @@ function islandora_collection_define_bundles() {
$mods_field_instance = array( $mods_field_instance = array(
'field_name' => ISLANDORA_MODS_FIELD, 'field_name' => ISLANDORA_MODS_FIELD,
'entity_type' => 'node', 'entity_type' => 'node',
'bundle' => ISLANDORA_COLLECTION_BUNDLE, 'bundle' => ISLANDORA_COLLECTION_CONTENT_TYPE,
'label' => $t("MODS"), 'label' => $t("MODS"),
'description' => $t("A MODS record for the Fedora resource"), 'description' => $t("A MODS record for the Fedora resource"),
'required' => FALSE, 'required' => FALSE,
@ -67,5 +42,5 @@ function islandora_collection_define_bundles() {
} }
// Add dcterms fields. // Add dcterms fields.
islandora_dcterms_attach_fields_to_bundle(ISLANDORA_COLLECTION_BUNDLE); islandora_dcterms_attach_fields_to_bundle(ISLANDORA_COLLECTION_CONTENT_TYPE);
} }

7
islandora_collection/islandora_collection.install

@ -9,11 +9,14 @@
* Implements hook_install(). * Implements hook_install().
*/ */
function islandora_collection_install() { function islandora_collection_install() {
module_load_include('inc', 'islandora_collection', 'include/bundles'); module_load_include('inc', 'islandora_collection', 'include/fields');
module_load_include('inc', 'islandora_collection', 'include/relations'); module_load_include('inc', 'islandora_collection', 'include/relations');
// Ensure the collection node type is available.
node_types_rebuild();
// Create the islandora:collection content type. // Create the islandora:collection content type.
islandora_collection_define_bundles(); islandora_collection_attach_default_fields();
// Create the pcdm:hasMember relation. // Create the pcdm:hasMember relation.
islandora_collection_define_relations(); islandora_collection_define_relations();

16
islandora_collection/islandora_collection.module

@ -5,7 +5,7 @@
* This is the new Islandora Collection module. * This is the new Islandora Collection module.
*/ */
define('ISLANDORA_COLLECTION_BUNDLE', 'collection'); define('ISLANDORA_COLLECTION_CONTENT_TYPE', 'islandora_collection');
/** /**
* Implements hook_views_api(). * Implements hook_views_api().
@ -17,6 +17,20 @@ function islandora_collection_views_api() {
); );
} }
/**
* Implements hook_node_info().
*/
function islandora_collection_node_info() {
return array(
ISLANDORA_COLLECTION_CONTENT_TYPE => array(
'name' => t("Collection"),
'base' => ISLANDORA_COLLECTION_CONTENT_TYPE,
'description' => t("A Drupal node modeling an pcdm:Collection."),
'has_title' => FALSE,
),
);
}
/** /**
* Function for using a form. * Function for using a form.
* *

Loading…
Cancel
Save