public function JuiceboxGalleryDrupal::buildEmbed in Juicebox HTML5 Responsive Image Galleries 7.2
Build a render array of the embed code for a Juicebox gallery after images and options have been added.
Note that this is different from JuiceboxGalleryInterface:renderEmbed() in that it handles ALL considerations for embedding. This includes the addition of the appropriate js and css which would otherwise need to be done independent of renderEmbed(). It also uses the Drupal theme system as opposed to just returning direct markup. Within Drupal this method should always be used instead of renderEmbed().
Parameters
string $xml_path: The path to the Juicebox XML for this gallery.
boolean $add_js: Whether-or-not to add the Juicebox library and gallery-specific javascript.
array $context: Optional contextual information that may be used in the display:
- conf_path: A Drupal path within the admin interface where the gallery can be configured. This may be used within administrative contextual links for the gallery if provided.
boolean $add_xml: It may be difficult or impossible to rebuild some types of formatters during a separate XML request, so this option offers a way around that by embedding the XML for the gallery directly into the HTML output. This XML can then be fetched from a request to this same page later via a sub-request. If TRUE xml-source-path and xml-source-id query strings are also added to the XML URL to help the XML building logic locate this XML data later. Setting this option may work around certain limitations but will likely lead to slower XML generation.
Return value
array Drupal render array for the embed code that describes a gallery.
Overrides JuiceboxGalleryDrupalInterface::buildEmbed
File
- includes/
JuiceboxGalleryDrupal.inc, line 104 - Class to extend a JuiceboxGalleryDecorator object with Drupal-specific logic and structures.
Class
- JuiceboxGalleryDrupal
- Class to extend a JuiceboxGalleryDecorator object with Drupal-specific logic and structures.
Code
public function buildEmbed($xml_path = '', $add_js = TRUE, $context = array(), $add_xml = FALSE) {
// Prep the ids that may be referenced.
$embed_id = $this
->getId();
$embed_xml_id = 'xml--' . $embed_id;
// If we are embedding the XML we also 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'] = current_path();
$embed_query_additions['xml-source-id'] = $embed_xml_id;
}
// Pass-through the current query paramaters and a checksum on the XML URL.
$current_query = drupal_get_query_parameters();
$xml_query = array_merge($current_query, array(
'checksum' => $this
->getChecksum(),
), $embed_query_additions);
$xml = array(
'path' => $xml_path,
'options' => array(
'query' => $xml_query,
),
);
// The returned render array will contain some common values no matter what
// output we produce (normal and debug).
$output = array(
'#c_links' => $this
->buildContextualLinks($xml_path, $context, $add_xml),
'#gallery_id' => $embed_id,
'#gallery_images' => $this
->getImages(TRUE),
'#gallery_options' => $this
->getOptions(TRUE),
'#xml' => $xml,
'#settings' => $this->settings,
'#suffix' => '',
);
// If "jb-debug" is active in the query we display debug info in place of
// the actual gallery.
if (array_key_exists('jb-debug', $current_query) && $this
->accessDebugDisplay()) {
$output['#theme'] = 'juicebox_debug_markup';
$output['#attached']['css'] = array(
drupal_get_path('module', 'juicebox') . '/css/admin_styles.css',
);
}
else {
$output['#theme'] = 'juicebox_embed_markup';
if ($add_js) {
// Add the main library via libraries API.
$output['#attached']['libraries_load'][] = array(
'juicebox',
);
// Add the JS gallery details as Drupal.settings.
$output['#attached']['js'][] = array(
'data' => array(
'juicebox' => array(
$embed_id => $this
->getJavascriptVars(url($xml['path'], $xml['options'])),
),
),
'type' => 'setting',
);
// Add some local JS (implementing Drupal.behaviors) that will process
// the Drupal.settings above into a new client-side juicebox object.
$output['#attached']['js'][] = drupal_get_path('module', 'juicebox') . '/js/juicebox_load.js';
}
if ($add_xml) {
$output['#suffix'] .= $this
->renderXml($embed_xml_id);
}
}
return $output;
}