From 69c741f4dca17b21ea885b94d25df5ed34653b8e Mon Sep 17 00:00:00 2001 From: James Wilson Date: Tue, 28 Aug 2018 09:49:54 -0500 Subject: [PATCH] Implement Twig best practices for ebsco result display #16 --- ebsco.module | 173 ++++++++----------------------- templates/ebsco-result.html.twig | 101 +++++++++++++++++- 2 files changed, 144 insertions(+), 130 deletions(-) diff --git a/ebsco.module b/ebsco.module index d9101be..1cb1dc1 100644 --- a/ebsco.module +++ b/ebsco.module @@ -17,10 +17,14 @@ * limitations under the License. */ -use Symfony\Component\HttpFoundation\RedirectResponse; + +use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; use Drupal\Core\Block\BlockPluginInterface; +use Drupal\Core\Link; use Drupal\Core\Url; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Cmf\Component\Routing\RouteObjectInterface; require_once __DIR__ . '/lib/EBSCODocument.php'; @@ -1151,163 +1155,74 @@ function template_preprocess_ebsco_advanced_search(&$variables) { * @see ebsco-result.tpl.php */ function template_preprocess_ebsco_result(&$variables) { - $params = $_REQUEST; $params['op'] = isset($params['op']) ? $params['op'] : 'Next'; - $_SESSION['EBSCO']['redirect'] = drupal_get_destination(); + $destination = \Drupal::destination()->getAsArray(); + + $_SESSION['EBSCO']['redirect'] = $destination; if (empty($Document)) { $Document = new EBSCODocument(); } $Document->retrieve(); - $record = $Document->record(); - - $variables['record'] = $record; - $lastSearch['count'] = $Document->record_count(); - $variables['count'] = $Document->record_count(); - - $lastSearch = isset($params['id']) ? $Document->search_read($params['id'], $params['op']) : 'fail'; - $variables['last_search'] = $_SESSION['EBSCO']['lastsearch']; - $detailRecordHTML=""; - - if (isset($record) ){ - - $id = \Drupal\Component\Utility\Html::escape($record->record_id()); - $fulltextUrl= \Drupal\Core\Url::fromRoute('ebsco.fulltext', array('id' => $id))->toString();; - $pdfUrl= \Drupal\Core\Url::fromRoute('ebsco.pdf', array('id' => $id))->toString(); - + $variables['record'] = $record = $Document->record(); - $detailRecordHTML='
' - .'
' - .'' + $lastSearch = isset($params['id']) ? $Document->search_read($params['id'], $params['op']) : []; + if (!empty($lastSearch)) { + $variables['last_search'] = $lastSearch; + $variables['current_index'] = $lastSearch['current_index']; - - .'' - .'
' - ; - - $detailRecordHTML.='
'; - - $detailRecordHTML.='
'; - } - $variables['detailrecord'] = $detailRecordHTML; - - - - - $request = \Drupal::request(); - if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) { - $route->setDefault('_title', $record->title); } } @@ -1519,4 +1434,4 @@ function auto_link($string) $string ); return $linkedString; -} \ No newline at end of file +} diff --git a/templates/ebsco-result.html.twig b/templates/ebsco-result.html.twig index b3bebc5..fd0f169 100644 --- a/templates/ebsco-result.html.twig +++ b/templates/ebsco-result.html.twig @@ -5,6 +5,7 @@ * * @see template_preprocess_ebsco_result() * + * @ingroup themeable * * Copyright [2017] [EBSCO Information Services] * @@ -21,7 +22,105 @@ * limitations under the License. */ #} +
+ + +