public function JuiceboxDisplayStyle::render in Juicebox HTML5 Responsive Image Galleries 8.3
Same name and namespace in other branches
- 8.2 src/Plugin/views/style/JuiceboxDisplayStyle.php \Drupal\juicebox\Plugin\views\style\JuiceboxDisplayStyle::render()
Render the display in this style.
Overrides StylePluginBase::render
File
- src/
Plugin/ views/ style/ JuiceboxDisplayStyle.php, line 226
Class
- JuiceboxDisplayStyle
- Plugin implementation of the 'juicebox' display style.
Namespace
Drupal\juicebox\Plugin\views\styleCode
public function render() {
$element = [];
$view = $this->view;
$settings = $this->options;
$display_name = isset($view->current_display) ? $view->current_display : 'default';
// Generate xml details.
$xml_route_info = [
'route_name' => 'juicebox.xml_viewsstyle',
'route_parameters' => [
'viewName' => $view
->id(),
'displayName' => $display_name,
],
'options' => [
'query' => $this
->argsToQuery() + $this->request->query
->all(),
],
];
// If we are previewing the view in the admin interface any changes made
// will not be propogated through to the XML until the view is saved. This
// can be very confusing as the preview will appear to be broken, so we
// simply hide the preview output.
if ($this->request
->get('_route') == 'entity.view.preview_form') {
$message = $this->stringTranslation
->translate("Juicebox galleries cannot be viewed as a live preview. Please save your view and visit the full page URL for this display to preview this gallery.");
$this
->messenger()
->addWarning($message);
return [
'#markup' => $message,
];
}
// Try building the gallery and its XML.
try {
// Initialize the gallery.
$gallery = $this->juicebox
->newGallery($xml_route_info['route_parameters']);
// Build the gallery.
$this
->buildGallery($gallery);
// Build field-specific contextual links.
$contextual = $this
->buildContextualLinks($xml_route_info);
// Create a render array with the gallery markup.
$element = $this->juicebox
->buildEmbed($gallery, $settings, $xml_route_info, TRUE, FALSE, $contextual);
} catch (\Exception $e) {
$message = 'Exception building Juicebox embed code for view: !message in %function (line %line of %file).';
watchdog_exception('juicebox', $e, $message);
}
return $element;
}