array( 'name' => t("Basic Image"), 'base' => ISLANDORA_BASIC_IMAGE_CONTENT_TYPE, 'description' => t("A Drupal node modeling a basic image pcdm:Object"), ), ); } /** * Implements hook_form(). */ function islandora_basic_image_form($node, array &$form_state) { return node_content_form($node, $form_state); } /** * Implements hook_form_FORM_ID_alter(). */ function islandora_basic_image_form_islandora_basic_image_node_form_alter(&$form, array &$form_state, $form_id) { $form['title']['#weight'] = -6; $form['obj'] = array( '#type' => 'file', '#title' => t('Basic Image'), '#description' => t('Upload your archival object to put in Fedora. This will generate new derivatives'), '#weight' => -5, ); // Add a collection picker if node is new (e.g. this is an insert form). $node = $form_state['node']; if (!isset($node->nid) || isset($node->is_new)) { // Construct list of options from db and a default. $from_db = db_select('node', 'n') ->fields('n', array('uuid', 'title')) ->condition('n.type', ISLANDORA_COLLECTION_CONTENT_TYPE) ->execute() ->fetchAllKeyed(); // Add the select to the form. $form['parent_collection'] = array( '#type' => 'select', '#title' => t('Parent Collection'), '#description' => t('Select the parent collection to add this to.'), '#options' => $from_db, '#weight' => -4, '#required' => TRUE, ); // Keep title on top. $form['title']['#weight'] = -7; // Tack on a custom submit handler to attach data on the entity for use // later on in the post action hooks. array_unshift($form['#submit'], 'islandora_basic_image_add_parent_uuid'); } } /** * Custom submit handler to pass along parent uuid. * * @param array $form * Drupal form. * @param array $form_state * Drupal form state. */ function islandora_basic_image_add_parent_uuid(array $form, array &$form_state) { $node = $form_state['node']; $node->parent_collection = ""; if (isset($form_state['values']['parent_collection'])) { $form_state['values']['field_fedora_has_parent']['und'][0]['value'] = $form_state['values']['parent_collection']; } } /** * Implements hook_rdf_mapping(). */ function islandora_basic_image_rdf_mapping() { module_load_include('inc', 'islandora', 'include/rdf_mapping'); $rdf_types = array( ISLANDORA_PCDM_OBJECT_RDF_TYPE, ISLANDORA_BASIC_IMAGE_RDF_TYPE, ); return islandora_get_default_rdf_mapping(ISLANDORA_BASIC_IMAGE_CONTENT_TYPE, $rdf_types); } /** * Implements hook_node_postinsert(). */ function islandora_basic_image_node_postinsert($node) { module_load_include('inc', 'islandora', 'include/utils'); if (islandora_ignore_hooks()) { return; } // Exit early if it's not a basic_image. if (strcmp($node->type, ISLANDORA_BASIC_IMAGE_CONTENT_TYPE) != 0) { return; } $parent_collection = $node->parent_collection; $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); // Set the options for httprl. $options = array( 'method' => 'POST', 'data' => array( 'mimetype' => $_FILES['files']['type']['obj'], 'node' => json_encode($node), ), ); // Add the obj file to the options if it exists. $has_obj = isset($_FILES['files']['tmp_name']['obj']); if ($has_obj) { $options['data']['files'] = array( 'obj' => array( $_FILES['files']['tmp_name']['obj'], ), ); } $url = "http://127.0.0.1:8181/cxf/islandora/image/$parent_collection"; httprl_request($url, $options); $response = httprl_send_request(); } /** * Implements hook_node_postupdate(). */ function islandora_basic_image_node_postupdate($node) { module_load_include('inc', 'islandora', 'include/utils'); if (islandora_ignore_hooks()) { return; } // Exit early if it's not a basic image. if (strcmp($node->type, ISLANDORA_BASIC_IMAGE_CONTENT_TYPE) != 0) { return; } $nodes = entity_uuid_load('node', array($node->uuid)); if (empty($nodes)) { return; } $node = array_pop($nodes); // Set the options for httprl. $options = array( 'method' => 'PUT', 'data' => array( 'mimetype' => $_FILES['files']['type']['obj'], 'node' => json_encode($node), ), ); // Add the obj file to the options if it exists. $has_obj = isset($_FILES['files']['tmp_name']['obj']); if ($has_obj) { $options['data']['files'] = array( 'obj' => array( $_FILES['files']['tmp_name']['obj'], ), ); } httprl_request("http://127.0.0.1:8181/cxf/islandora/image/{$node->uuid}", $options); $response = httprl_send_request(); } /** * Implements hook_node_postdelete(). */ function islandora_basic_image_node_postdelete($node) { module_load_include('inc', 'islandora', 'include/utils'); if (islandora_ignore_hooks()) { return; } // Exit early if it's not a collection. if (strcmp($node->type, ISLANDORA_BASIC_IMAGE_CONTENT_TYPE) != 0) { return; } $uuid = $node->uuid; httprl_request("http://127.0.0.1:8181/cxf/islandora/image/$uuid", array( 'method' => 'DELETE', )); $response = httprl_send_request(); }