Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function buildEmbed(JuiceboxGalleryInterface $gallery, $settings, $xml_route_info, $add_js = TRUE, $add_xml = FALSE, $contextual = array())
 {
     // Merge all settings.
     $settings = $settings + $this->getGlobalSettings();
     // Set some defaults for the route info.
     $xml_route_info += array('route_name' => '', 'route_parameters' => array(), 'options' => array());
     // Prep the ids that may be used.
     $embed_id = $gallery->getId();
     $embed_xml_id = 'xml--' . $embed_id;
     // Construct the base render array for the gallery.
     $output = array('#gallery' => $gallery, '#theme' => 'juicebox_embed_markup', '#settings' => $settings, '#attached' => array(), '#contextual_links' => $contextual + array('juicebox_conf_global' => array('route_parameters' => array())), '#cache' => array('tags' => array('juicebox_gallery')), '#suffix' => '');
     // Process JS additions.
     if ($add_js) {
         // If we are also embedding the XML we want to set some query string
         // values on the XML URL that will allow the XML build methods to fetch
         // it later.
         $embed_query_additions = array();
         if ($add_xml) {
             $embed_query_additions['xml-source-path'] = trim($this->current_path_stack->getPath(), '/');
             $embed_query_additions['xml-source-id'] = $embed_xml_id;
         }
         // Add some query params that apply to all types of Juicebox galleries and
         // generate the final XML URL.
         $xml_query_additions = array_merge(array('checksum' => $gallery->getChecksum()), $embed_query_additions);
         $xml_options = array_merge_recursive(array('query' => $xml_query_additions), $xml_route_info['options']);
         $xml_url = $this->urlGenerator->generateFromRoute($xml_route_info['route_name'], $xml_route_info['route_parameters'], $xml_options);
         // Add the main library.
         $output['#attached']['library'][] = 'juicebox/juicebox';
         // Add the JS gallery details as Drupal.settings.
         $output['#attached']['drupalSettings']['juicebox'] = array($embed_id => $gallery->getJavascriptVars($xml_url));
         // Add some local JS (implementing Drupal.behaviors) that will process
         // the Drupal.settings above into a new client-side juicebox object.
         $output['#attached']['library'][] = 'juicebox/juicebox.local';
     }
     if ($add_xml) {
         $output['#suffix'] .= $gallery->renderXml($embed_xml_id);
     }
     // Ensure that our suffix is not further sanitized.
     $output['#suffix'] = SafeMarkup::format($output['#suffix'], array());
     return $output;
 }