From 7517be2a3ef8517c9735632c1927ec3ea857a142 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Mon, 28 May 2012 19:39:32 -0300 Subject: [PATCH 1/3] moved datastream form functions to datastream inc and started properties form --- includes/datastream.inc | 167 +++++++++++++++++++++++++++++++++ includes/object_properties.inc | 42 +++++++++ islandora.module | 166 +++++++------------------------- 3 files changed, 245 insertions(+), 130 deletions(-) create mode 100644 includes/object_properties.inc diff --git a/includes/datastream.inc b/includes/datastream.inc index 980977c4..2c7e58b2 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -172,3 +172,170 @@ function islandora_get_add_datastream_form($object_id, &$form_state) { } return $form; } + +/** + * Default implmentation currently only does M (managed datastreams) + * other modules can hook form alter to add other functionality + * @global string $base_url + * @global object $user + * Drupal user + * @param array $form + * @param array $form_state + * @return type + */ +function islandora_add_datastream_form_submit($form, &$form_state) { + global $base_url; + if (!empty($form_state['submit']) && $form_state['submit'] == 'OK') { + $form_state['rebuild'] = TRUE; + return; + } + + $file = $form_state['values']['add-stream-file-location']; + $file = drupal_realpath($file); + $object_id = $form_state['values']['pid']; + $dsid = $form_state['values']['stream_id']; + $ds_label = $form_state['values']['stream_label']; // Add the file extention to the end of the label.; + //$dformat = $mimetype->getType($file); + $controlGroup = "M"; + //if ($dformat == 'text/xml') { + // $controlGroup = 'X'; + //} + global $user; + try { + $restConnection = new RestConnection($user); + $fedora_object = new FedoraObject($object_id, $restConnection->repository); + $ds = $fedora_object->constructDatastream($dsid, $controlGroup); + $ds->label = $ds_label; + $ds->setContentFromFile($file); + $fedora_object->ingestDatastream($ds); + $d_file = file_load($form_state['values']['fid']); + file_delete($d_file); + } catch (exception $e) { + drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); + return; + } + $form_state['rebuild'] = TRUE; +} + +/** + * validates this datastream id against its allowed mimetypes in the dscomposite + * of its content models. + * @param array $form + * @param array $form_state + * @return boolean + */ +function islandora_add_datastream_form_validate($form, &$form_state) { + module_load_include('inc', 'islandora', 'includes/MimeClass'); + $mimetype = new MimeClass(); + if ($form_state['clicked_button']['#value'] == 'OK') { + $form_state['rebuild'] = TRUE; + return; + } + $dsid = $form_state['values']['stream_id']; + $dsLabel = $form_state['values']['stream_label']; + if (strlen($dsid) > 64) { + form_set_error('', t('Data stream ID cannot be more than 64 characters.')); + return FALSE; + } + if (!(preg_match("/^[a-zA-Z]/", $dsid))) { + form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid)))); + return FALSE; + } + if (strlen($dsLabel) > 64) { + form_set_error('', t('Data stream Label cannot be more than 64 characters.')); + return FALSE; + } + if (strpos($dsLabel, '/')) { + form_set_error('', t('Data stream Label cannot contain a "/".')); + return FALSE; + } + $mimetype = new MimeClass(); + $unused_dsids = islandora_get_unused_dsids($form_state['values']['pid']); + $types_allowed = $unused_dsids[$dsid]; + $arr = array(); + foreach ($types_allowed as $type) { + $arr[] = $mimetype->getExtension($type); + } + $file = file_save_upload('add-stream-file-location', array('file_validate_extensions' => $arr)); + if ($file) { + $form_state['values']['add-stream-file-location'] = $file->uri; + $form_state['values']['fid'] = $file->fid; //so we can load it to delete later + } + else { + form_set_error('add-stream-file-location', t('There was no file uploaded')); + } +} + + +/** + * buids the default add datastream form + * @param string $object_id + * @param array $form_state + * @return array + * a form ready to be rendered with a call to Drupal render + */ +function islandora_add_datastream_form($form, &$form_state, $object_id) { + $unused_dsids = islandora_get_unused_dsids($object_id); //$defined_dsids; + $form = array(); + $form['add_fieldset'] = array( + '#type' => 'fieldset', + '#title' => 'Add a datastream', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['add_fieldset']['add_datastream_label'] = array( + '#value' => t('

Add Datastream:

'), + '#weight' => -10, + ); + + $form['pid'] = array( + '#type' => 'hidden', + '#value' => "$object_id" + ); + + $form['add_fieldset']['stream_label'] = array( + '#title' => 'Datastream Label', + '#required' => 'TRUE', + '#description' => t('A Human readable label'), + '#type' => 'textfield' + ); + + $form['#attributes']['enctype'] = 'multipart/form-data'; + $form['add_fieldset']['add-stream-file-location'] = array( + '#type' => 'file', + '#title' => t('Upload Document'), + '#size' => 48, + // '#required'=>'TRUE', + '#description' => t('The file to upload.') + ); + $form['#redirect'] = "islandora/object/$object_id/"; + $form['add_fieldset']['submit'] = array( + '#type' => 'submit', + '#value' => t('Add Datastream') + ); + + if (!empty($unused_dsids)) { + $dsidsForForm = array(); + foreach ($unused_dsids as $key => $value) { + $dsidsForForm[$key] = $key; + } + $form['add_fieldset']['stream_id'] = array( + '#type' => 'select', + '#title' => t('Datastream ID'), + '#default_value' => variable_get('feed_item_length', 'teaser'), + '#weight' => '-1', + '#description' => t('Datastream IDs defined by the content model.'), + ); + $form['add_fieldset']['stream_id']['#options'] = $dsidsForForm; + } + else { + $form['add_fieldset']['stream_id'] = array( + '#title' => 'Datastream ID', + '#required' => 'TRUE', + '#description' => t('An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores.'), + '#type' => 'textfield', + '#weight' => -1, + ); + } + return $form; +} diff --git a/includes/object_properties.inc b/includes/object_properties.inc new file mode 100644 index 00000000..8897ff3b --- /dev/null +++ b/includes/object_properties.inc @@ -0,0 +1,42 @@ + 'hidden', + '#value' => $object_id, + ); + + $form['object_label'] = array( + '#title' => t('Item Label'), + '#default_value' => $islandora_object->label, + '#required' => 'TRUE', + '#description' => t('A Human readable label'), + '#type' => 'textfield' + ); + $form['object_owner'] = array( + '#title' => t('Owner'), + '#default_value' => $islandora_object->owner, + '#required' => FALSE, + '#description' => t('The owner id'), + '#type' => 'textfield', + ); + $form['object_state'] = array( + '#title' => t('State'), + '#default_value' => $islandora_object->state, + '#required' => TRUE, + '#description' => t('The items state, either active, inactive or deleted'), + '#type' => 'select', + '#options' => array ('A' => 'Active', 'I' => 'Inactive', 'D'=>'Deleted'), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => 'Update Properties', + ); + return $form; +} +?> diff --git a/islandora.module b/islandora.module index 7a0e89ef..521101bc 100644 --- a/islandora.module +++ b/islandora.module @@ -108,16 +108,16 @@ function islandora_menu() { 'access arguments' => array(FEDORA_VIEW), ); - /* + $items['islandora/object/%/add'] = array( 'title' => 'Add to an object', - //'file' => 'includes/add-menu.inc', - 'page callback' => 'islandora_add_datastream', - 'page arguments' => array(2), + 'file' => 'includes/datastream.inc', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('islandora_add_datastream_form',2), 'type' => MENU_NORMAL_ITEM, 'access arguments' => array(FEDORA_ADD_DS) ); - */ + $items['islandora/object/%/view'] = array( 'title' => 'View', @@ -155,8 +155,9 @@ function islandora_menu() { $items['islandora/object/%/manage/properties'] = array( 'title' => 'Properties', - 'page callback' => 'islandora_edit_properties', - 'page arguments' => array(2), + 'page callback' => 'drupal_get_form', + 'file' => 'includes/object_properties.inc', + 'page arguments' => array('islandora_edit_properties_form',2), 'type' => MENU_LOCAL_TASK, 'access arguments' => array(FEDORA_MODIFY_STATE), 'weight' => -5, @@ -344,12 +345,25 @@ function islandora_edit_object($object_id) { return $output; } +/** + * edit properties form + * @param type $object_id + * @return string + */ function islandora_edit_properties($object_id) { - return 'edit properties ' . $object_id; + $object = islandora_get_object($object_id); + if (isset($object)) { + module_load_include('inc','islandora','includes/object_properties'); + $form = drupal_get_form('islandora_edit_properties_form', $object); + drupal_set_title($object->label); + return drupal_render($form); + } + return ""; } /** * builds a default page for the edit tab + * * @param object $fedora_object * A tuque Fedora Object */ @@ -548,25 +562,10 @@ function islandora_permission() { } /** - * renders the add datastream from. - * @param string $object_id - * @return type + * preprocess for the default view template + * @global string $base_url + * @param array $variables */ -function islandora_add_datastream($object_id) { - if (!isset($object_id)) { - drupal_set_message(t('Cannot add datastream to object, object id not set')); - return; - } - $object = islandora_get_object($object_id); - if (isset($object)) { - $form = drupal_get_form('islandora_add_datastream_form', $object); - drupal_set_title($object->label); - return drupal_render($form); - } - return ""; - // hook form alter might be enough here may not need a module invoke all -} - function islandora_preprocess_islandora_default(&$variables) { $islandora_object = $variables['islandora_object']; module_load_include('inc', 'islandora', 'includes/islandora_dublin_core'); @@ -586,6 +585,12 @@ function islandora_preprocess_islandora_default(&$variables) { } } +/** + * a helper function to get a connection and return an object + * @global object $user + * @param string $object_id + * @return FedoraObject + */ function islandora_get_object($object_id) { module_load_include('inc', 'islandora', 'RestConnection'); global $user; @@ -600,117 +605,18 @@ function islandora_get_object($object_id) { } /** - * Builds the default add a datastream form. - * @param array $form - * @param array $form_state - * @param Object $islandora_object - * @return type - */ -function islandora_add_datastream_form($form, &$form_state, $islandora_object) { - module_load_include('inc', 'islandora', 'includes/datastream'); - $form = islandora_get_add_datastream_form($islandora_object->id, $form_state); - return $form; -} - -/** - * Default implmentation currently only does M (managed datastreams) - * other modules can hook form alter to add other functionality + * preprocess the edit template * @global string $base_url - * @global object $user - * Drupal user - * @param array $form - * @param array $form_state - * @return type + * @param array $variables + * theme variables for the edit template */ -function islandora_add_datastream_form_submit($form, &$form_state) { - global $base_url; - if (!empty($form_state['submit']) && $form_state['submit'] == 'OK') { - $form_state['rebuild'] = TRUE; - return; - } - - $file = $form_state['values']['add-stream-file-location']; - $file = drupal_realpath($file); - $object_id = $form_state['values']['pid']; - $dsid = $form_state['values']['stream_id']; - $ds_label = $form_state['values']['stream_label']; // Add the file extention to the end of the label.; - //$dformat = $mimetype->getType($file); - $controlGroup = "M"; - //if ($dformat == 'text/xml') { - // $controlGroup = 'X'; - //} - global $user; - try { - $restConnection = new RestConnection($user); - $fedora_object = new FedoraObject($object_id, $restConnection->repository); - $ds = $fedora_object->constructDatastream($dsid, $controlGroup); - $ds->label = $ds_label; - $ds->setContentFromFile($file); - $fedora_object->ingestDatastream($ds); - $d_file = file_load($form_state['values']['fid']); - file_delete($d_file); - } catch (exception $e) { - drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); - return; - } - $form_state['rebuild'] = TRUE; -} - -/** - * validates this datastream id against its allowed mimetypes in the dscomposite - * of its content models. - * @param array $form - * @param array $form_state - * @return boolean - */ -function islandora_add_datastream_form_validate($form, &$form_state) { - module_load_include('inc', 'islandora', 'includes/MimeClass'); - $mimetype = new MimeClass(); - if ($form_state['clicked_button']['#value'] == 'OK') { - $form_state['rebuild'] = TRUE; - return; - } - $dsid = $form_state['values']['stream_id']; - $dsLabel = $form_state['values']['stream_label']; - if (strlen($dsid) > 64) { - form_set_error('', t('Data stream ID cannot be more than 64 characters.')); - return FALSE; - } - if (!(preg_match("/^[a-zA-Z]/", $dsid))) { - form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid)))); - return FALSE; - } - if (strlen($dsLabel) > 64) { - form_set_error('', t('Data stream Label cannot be more than 64 characters.')); - return FALSE; - } - if (strpos($dsLabel, '/')) { - form_set_error('', t('Data stream Label cannot contain a "/".')); - return FALSE; - } - $mimetype = new MimeClass(); - $unused_dsids = islandora_get_unused_dsids($form_state['values']['pid']); - $types_allowed = $unused_dsids[$dsid]; - $arr = array(); - foreach ($types_allowed as $type) { - $arr[] = $mimetype->getExtension($type); - } - $file = file_save_upload('add-stream-file-location', array('file_validate_extensions' => $arr)); - if ($file) { - $form_state['values']['add-stream-file-location'] = $file->uri; - $form_state['values']['fid'] = $file->fid; //so we can load it to delete later - } - else { - form_set_error('add-stream-file-location', t('There was no file uploaded')); - } -} - function islandora_preprocess_islandora_default_edit(&$variables) { $islandora_object = $variables['islandora_object']; global $base_url; $datastreams = array(); $variables['islandora_editmetadata_url'] = $base_url . '/islandora/edit_form/' . $islandora_object->id; - $variables['add_datastream_form'] = drupal_get_form('islandora_add_datastream_form', $islandora_object); + module_load_include('inc','islandora','includes/datastream'); + $variables['add_datastream_form'] = drupal_get_form('islandora_add_datastream_form', $islandora_object->id); foreach ($islandora_object as $ds) { $datastreams['download_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/download'; $datastreams['view_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/view'; From 90ce74cd788412db9ffa76bc7012d2ad98b31246 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Mon, 28 May 2012 20:14:38 -0300 Subject: [PATCH 2/3] start of object propertes submit function --- includes/object_properties.inc | 47 +++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/includes/object_properties.inc b/includes/object_properties.inc index 8897ff3b..34a7b67e 100644 --- a/includes/object_properties.inc +++ b/includes/object_properties.inc @@ -1,5 +1,50 @@ owner){ + $params['ownerId'] = check_plain($owner); + $submit = TRUE; + } + if(isset($state) && $state != $islandora_object->state){ + $params['state'] = check_plain($state); + $submit = TRUE; + } + if(isset($label) && $label != $islandora_object->label){ + $params['label'] = check_plain($label); + $submit = TRUE; + } + if($submit){ + $islandora_object->modifyObject($params); + } +} + +/** + * + * @param array $form + * @param array $form_state + * @param string $object_id + * an object id + * @return array + */ function islandora_edit_properties_form ($form, &$form_state, $object_id){ $form = array(); $islandora_object = islandora_get_object($object_id); @@ -29,7 +74,7 @@ function islandora_edit_properties_form ($form, &$form_state, $object_id){ '#title' => t('State'), '#default_value' => $islandora_object->state, '#required' => TRUE, - '#description' => t('The items state, either active, inactive or deleted'), + '#description' => t('The items state one of active, inactive or deleted'), '#type' => 'select', '#options' => array ('A' => 'Active', 'I' => 'Inactive', 'D'=>'Deleted'), ); From 0f8bcdc7808f4897008b6f9b774c7dc50c03cde2 Mon Sep 17 00:00:00 2001 From: krisbulman Date: Tue, 29 May 2012 00:32:22 -0300 Subject: [PATCH 3/3] moved inline definition list class to islandora base css, fixed up object css for truncating labels and widths at smaller sizes, added default islandora class to templates moved base css to correct location --- css/islandora.base.css | 52 ++++++++++++++++++ css/islandora.theme.css | 54 ++----------------- islandora-object.tpl.php | 28 +++++----- .../css/islandora_basic_image.theme.css | 52 +----------------- .../islandora-basic-image.tpl.php | 4 +- 5 files changed, 75 insertions(+), 115 deletions(-) diff --git a/css/islandora.base.css b/css/islandora.base.css index 13dd8637..0a8b3662 100644 --- a/css/islandora.base.css +++ b/css/islandora.base.css @@ -5,4 +5,56 @@ Purpose of the stylesheet follows. */ +.islandora img { + max-width: 100%; + *width: 100%; +} +.islandora * { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} + +/* + * These rules will display DTs/DDs as columns. + * Constructs must follow a key/value pair pattern. + * The three last declarations are meant to kill white space between DTs/DDs + * (result of inline-block styling) + */ + +dl.islandora-inline-metadata { + margin: 0 auto; + letter-spacing: -0.31em; + *letter-spacing:normal; + word-spacing: -0.43em; +} + +.islandora-inline-metadata dt { + margin-right: -1px; + width: 15.625%; + font-weight: normal; + font-weight: bold; + padding-right: 0; +} + +.islandora-inline-metadata dd { + width: 84.375%; + padding-left: 40px; +} + +/* + * In this rule, we reset the white-space (see hack above) + */ +.islandora-inline-metadata dt, +.islandora-inline-metadata dd { + display: inline-block; + *display: inline; + zoom: 1; + letter-spacing: normal; + word-spacing: normal; + vertical-align: top; + padding-top: 6px; + padding-bottom: 4px; + margin: 0; +} diff --git a/css/islandora.theme.css b/css/islandora.theme.css index ad0ae79d..e299b9db 100644 --- a/css/islandora.theme.css +++ b/css/islandora.theme.css @@ -9,71 +9,27 @@ * Thumbnails float optionally to the left or right of descriptive lists. */ -.islandora-object-thumb img { - max-width: 100%; - *width: 100%; -} - -dl.islandora-object-thumb { +dl.islandora-object-tn { float: left; - width: 15%; - margin: 0.75em auto; -} - -.islandora-object-thumb dt, -.islandora-object-thumb dd { + width: 20.8333%; + padding: 0 10px 0 0; margin: 0; } -/* - * These rules will display DTs/DDs as columns. - * Constructs must follow a key/value pair pattern. - * The three last declarations are meant to kill white space between DTs/DDs - * (result of inline-block styling) - */ dl.islandora-object-fields { float: right; - width:83%; - margin: 0.75em auto; - letter-spacing:-0.34em; - *letter-spacing:normal; - word-spacing:-0.44em; + width:79.1666%; border-top:3px solid #ddd; -} +} -/* - * The width + left/right padding of DTs/DDs equals 88% when compensating for an image - */ .islandora-object-fields dt { - margin-right:-1px; - width:22.5%; font-weight: bold; } -.islandora-object-fields dd { - width:67%; -} - -/* - * In this rule, we reset the white-space (see hack above) - */ .islandora-object-fields dt, .islandora-object-fields dd { - display:inline-block; - *display:inline; - zoom:1; - letter-spacing:normal; - word-spacing:normal; - vertical-align:top; padding:6px 2% 4px; - margin:0; border-top:1px solid #ddd; - -ms-word-break: break-all; - word-break: break-all; - word-break: break-word; /* webkit */ --webkit-hyphens: auto; - -moz-hyphens: auto; - hyphens: auto; } .islandora-object-fields dt.first, diff --git a/islandora-object.tpl.php b/islandora-object.tpl.php index ca7a67ed..06b11cab 100644 --- a/islandora-object.tpl.php +++ b/islandora-object.tpl.php @@ -69,25 +69,25 @@ drupal_set_title($islandora_object->label); // } ?> -
+

Details

-
+
'); ?>
-
- - $value): ?> -
- -
-
- -
- - -
+
diff --git a/islandora_basic_image/css/islandora_basic_image.theme.css b/islandora_basic_image/css/islandora_basic_image.theme.css index 1c74b737..e7b31c4d 100644 --- a/islandora_basic_image/css/islandora_basic_image.theme.css +++ b/islandora_basic_image/css/islandora_basic_image.theme.css @@ -5,12 +5,6 @@ Purpose of the stylesheet follows. */ -.islandora-basic-image-object img { - height: auto; - max-width: 100%; - *width: 100%; -} - .islandora-basic-image-content, .islandora-basic-image-sidebar { display: inline; @@ -19,30 +13,14 @@ .islandora-basic-image-metadata { display: block; - clear: both + clear: both; } dl.islandora-basic-image-fields { width:100%; - margin: 0 auto; - letter-spacing:-0.31em; - *letter-spacing:normal; - word-spacing:-0.43em; -} - -/* - * The width + left/right padding of DTs/DDs equals 88% when compensating for an image - */ - -.islandora-basic-image-metadata * { - -moz-box-sizing: border-box; - -webkit-box-sizing: border-box; - box-sizing: border-box; } .islandora-basic-image-metadata dt { - margin-right:-1px; - width:15.625%; font-weight: normal; text-align: right; font-weight: bold; @@ -50,24 +28,12 @@ dl.islandora-basic-image-fields { } .islandora-basic-image-metadata dd { - width:84.375%; padding-left: 40px; } -/* - * In this rule, we reset the white-space (see hack above) - */ + .islandora-basic-image-metadata dt, .islandora-basic-image-metadata dd { - display:inline-block; - *display:inline; - zoom:1; - letter-spacing:normal; - word-spacing:normal; - vertical-align:top; - padding-top: 6px; - padding-bottom: 4px; - margin:0; border-top:1px solid #e5e5e5; } @@ -84,22 +50,8 @@ body.two-sidebars .islandora-basic-image-sidebar { width: 100%; } -.islandora-basic-image-sidebar, -.islandora-basic-image-sidebar, -body.one-sidebar .islandora-basic-image-sidebar, -body.two-sidebars .islandora-basic-image-sidebar { - width: 100%; -} - @media all and (min-width: 768px) { - body.no-sidebars .islandora-basic-image-content, - body.no-sidebars .islandora-basic-image-sidebar { - -moz-box-sizing: border-box; - -webkit-box-sizing: border-box; - box-sizing: border-box; - } - body.no-sidebars .islandora-basic-image-content { width: 60%; padding: 0 20px 0 0; diff --git a/islandora_basic_image/islandora-basic-image.tpl.php b/islandora_basic_image/islandora-basic-image.tpl.php index 596a5233..a1a61da5 100644 --- a/islandora_basic_image/islandora-basic-image.tpl.php +++ b/islandora_basic_image/islandora-basic-image.tpl.php @@ -23,7 +23,7 @@ ?> -
+
@@ -36,7 +36,7 @@