getReserves(); if (empty($html)) { return ''; } return [ '#theme' => 'upei_roblib_reserves_block', '#atom_to_html' => [ '#markup' => $html, ], ]; } /** * {@inheritdoc} */ public function getCacheMaxAge() { //Reading dynamic content from external source so no caching. return 0; } /** * Queries Evergreen for an Atom XML feed based on book bag list. * * @return string * HTML created from Atom XML feed. */ protected function getReserves() { $node = \Drupal::routeMatch()->getParameter('node'); $html = ''; if ($node && $node instanceof \Drupal\node\NodeInterface && $node->bundle() == 'course_reserve') { $book_bag_id = (string) $node->field_bookbag_id->value; if (empty($book_bag_id)) { return ''; } //The evergreen ILS base URL. $book_bag_base_url = 'http://islandpines.roblib.upei.ca/opac/extras/feed/bookbag/atom-full/'; try { $response = \Drupal::httpClient()->get($book_bag_base_url . $book_bag_id); $atom = (string) $response->getBody(); if (empty($atom)) { return ''; } } catch (RequestException $e) { return ''; } $path = \Drupal::service('extension.list.module')->getPath('upei_roblib_reserves'); $xslt = new \XSLTProcessor(); $xsl = new \DOMDocument(); $xsl->load($path . '/xsl/atom2html.xsl'); $xslt->importStylesheet($xsl); $xml = new \DomDocument(); $xml->loadXML($atom); $html = $xslt->transformToXML($xml); } return $html; } }