You are here

public function JuiceboxXmlField::getXml in Juicebox HTML5 Responsive Image Galleries 7.2

Get the XML based on loaded data.

Return value

string Returns XML data describing a Juicebox gallery.

Overrides JuiceboxXmlInterface::getXml

File

plugins/JuiceboxXmlField.inc, line 103
Juicebox XML loader that's used to load (and build via loaded methods) the XML associated with a Drupal field formatter plugin.

Class

JuiceboxXmlField
Class to load and build the XML associated with a Drupal field formatter plugin.

Code

public function getXml() {

  // Build the field and gallery. This is easiest to do by simply calling
  // field_view_field (as it handles all needed sub-processes).
  $field = field_view_field($this->entityType, $this->entity, $this->fieldName, $this->displayName);

  // See if if the galley is actually built. field_view_field() typically
  // triggers the Juicebox init and build processes, and passes-back the
  // built gallery, but under certain caching situations these may be skipped
  // (e.g., if the raw field html is returned from a cache instead of calling
  // the formatter logic).
  $juicebox = $this
    ->getJuiceboxFromData($field);
  if (!$juicebox) {

    // Load the data needed to build the gallery manually.
    $this
      ->loadFormatterData();

    // Initalize a new gallery.
    $juicebox = juicebox();
    $juicebox
      ->init($this->idArgs, $this->settings, $field['#items']);

    // Manually build the gallery via the field formatter methods.
    juicebox_field_build_gallery($juicebox, $field['#items']);
  }

  // Render the XML.
  return $juicebox
    ->renderXml();
}