From e3a1b3bf61d531e9c33c96fae3d96be5117c685f Mon Sep 17 00:00:00 2001 From: "Francisco J. Seva" Date: Tue, 12 Sep 2017 10:19:10 +0200 Subject: [PATCH] Add logic to allow trim title and authors. --- ebsco/ebsco.module | 26 ++++++++++++++++++++++++++ ebsco/templates/ebsco-results.tpl.php | 14 ++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/ebsco/ebsco.module b/ebsco/ebsco.module index f3b0abb..5bb08ab 100644 --- a/ebsco/ebsco.module +++ b/ebsco/ebsco.module @@ -68,6 +68,10 @@ function ebsco_theme() { ), 'ebsco_results' => array( 'template' => 'templates/ebsco-results', + 'variables' => array( + 'trim_title' => FALSE, + 'trim_authors' => FALSE, + ), ), 'ebsco_side_facets' => array( 'template' => 'templates/ebsco-side-facets', @@ -216,6 +220,25 @@ function ebsco_admin() { '#required' => TRUE, ); + $form['ebsco_general']['ebsco_title_trim'] = array( + '#type' => 'textfield', + '#title' => t('Trim result Title'), + '#default_value' => variable_get('ebsco_title_trim', 0), + '#size' => 3, + '#maxlength' => 3, + '#description' => t('Title maximum number of characters to be displayed when an item is render in search result page.'), + '#required' => TRUE, + ); + + $form['ebsco_general']['ebsco_authors_trim'] = array( + '#type' => 'textfield', + '#title' => t('Trim result Authors'), + '#default_value' => variable_get('ebsco_authors_trim', 0), + '#size' => 3, + '#maxlength' => 3, + '#description' => t('Authors maximum number of characters to be displayed when an item is render in search result page.'), + '#required' => TRUE, + ); return system_settings_form($form); } @@ -904,6 +927,9 @@ function template_preprocess_ebsco_results(&$variables) { $variables['relatedContent'] = $_ebsco_document->relatedContent(); $variables['autoSuggestTerms'] = $_ebsco_document->autoSuggestTerms(); $variables['lookfor'] = ''; + $variables['trim_title'] = variable_get('ebsco_title_trim', 0); + $variables['trim_authors'] = variable_get('ebsco_authors_trim', 0); + if (isset($params['lookfor'])) { $variables['lookfor'] = $params['lookfor']; } diff --git a/ebsco/templates/ebsco-results.tpl.php b/ebsco/templates/ebsco-results.tpl.php index e9d8ae6..8219728 100644 --- a/ebsco/templates/ebsco-results.tpl.php +++ b/ebsco/templates/ebsco-results.tpl.php @@ -230,6 +230,16 @@
    title) > $trim_title) { + $record->title = truncate_utf8($record->title, $trim_title, TRUE, TRUE, 1); + } + + // Trim Authors if needed. + if ($trim_authors && strlen($record->authors) > $trim_authors) { + $record->authors = truncate_utf8(implode(',',explode('
    ', $record->authors)), $trim_authors, TRUE, TRUE, 1); + } + $id = check_plain($record->record_id()); $recordUrl = url('ebsco/result', array('query' => array('id' => $id))); $fulltextUrl = url('ebsco/fulltext', array('query' => array('id' => $id))); @@ -265,7 +275,7 @@ echo "

    "; } elseif ($record->title){ - echo '' . $record->title . ''; + echo '' . $record->title . ''; } ?> @@ -290,7 +300,7 @@ echo '' . $record->summary . '
    '; } - if (!empty($record->subjects)){ + if (!empty($record->subjects) && !$hide_record_subject){ echo '' . t('Subjects') . ':' . str_replace('
    ', ', ', $record->subjects) . '
    '; }