Skip to content

Commit

Permalink
Add a date format per field. (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordandukart authored and DiegoPino committed Aug 1, 2018
1 parent dc94fb7 commit e60b704
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions includes/config.inc
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,14 @@ function islandora_solr_metadata_config_field_form($form, &$form_state, $config_
'#default_value' => $get_default('uri_replacement', ''),
'#autocomplete_path' => 'islandora_solr/autocomplete_luke',
);
if (islandora_solr_is_date_field($field_name)) {
$set['date_format'] = array(
'#type' => 'textfield',
'#title' => t('Date format'),
'#default_value' => $get_default('date_format', ''),
'#description' => t('The format of the date, as it will be displayed in the search results. Use <a href="!url" target="_blank">PHP date()</a> formatting. Works best when the date format matches the granularity of the source data. Otherwise it is possible that there will be duplicates displayed.', array('!url' => 'http://php.net/manual/function.date.php')),
);
}
// Add in truncation fields for metadata field.
$truncation_config = array(
'default_values' => array(
Expand Down
5 changes: 4 additions & 1 deletion theme/theme.inc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ function islandora_solr_metadata_query_fields($object, &$solr_fields) {
'hyperlink' => 0,
'formatter' => NULL,
'uri_replacement' => '',
'date_format' => '',
);
// Replace URI or PID with a configured field.
if (!empty($field_config['uri_replacement'])) {
Expand Down Expand Up @@ -263,7 +264,9 @@ function islandora_solr_metadata_query_fields($object, &$solr_fields) {
));
}
}

if (islandora_solr_is_date_field($solr_field) && !empty($solr_fields[$solr_field]['date_format'])) {
$value = format_date(strtotime($value), 'custom', $solr_fields[$solr_field]['date_format'], 'UTC');
}
if (is_callable($field_config['formatter'])) {
$value = call_user_func($field_config['formatter'], $value);
}
Expand Down

0 comments on commit e60b704

Please sign in to comment.