/** * {@inheritdoc} */ public function render() { $element = array(); $view = $this->view; $settings = $this->options; $display_name = isset($view->current_display) ? $view->current_display : 'default'; $view_args = empty($view->args) ? array() : $view->args; // Generate xml details. $xml_route_info = array('route_name' => 'juicebox.xml_viewsstyle', 'route_parameters' => array('viewName' => $view->id(), 'displayName' => $display_name), 'options' => array('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."); drupal_set_message($message, 'warning'); return array('#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; }
/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $element = array(); // If there are no images, don't do anything else. if ($items->isEmpty()) { return array(); } $entity = $items->getEntity(); $field_instance = $items->getFieldDefinition(); $entity_type_id = $entity->getEntityTypeId(); $entity_id = $entity->id(); $field_name = $field_instance->getName(); $display_name = $this->viewMode; $add_js = TRUE; // Check for incompatible view modes - see issue #2217791 if ($display_name == 'search_result' || $display_name == 'search_index') { $add_js = FALSE; } // The gallery shown in preview view will only display field data from the // previously saved version (that is the only version the XML generation // methods will have access to). Display a warning because of this. if (!empty($entity->in_preview)) { drupal_set_message(t('Juicebox galleries may not display correctly in preview mode. Any edits made to gallery data will only be visible after all changes are saved.'), 'warning', FALSE); } // Generate xml details. $xml_route_info = array('route_name' => 'juicebox.xml_field', 'route_parameters' => array('entityType' => $entity_type_id, 'entityId' => $entity_id, 'fieldName' => $field_name, 'displayName' => $display_name), 'options' => array('query' => $this->request->query->all())); // 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, $items); // Build field-specific contextual links. $contextual = $this->buildContextualLinks($xml_route_info, $entity_type_id); // Create a render array with the gallery markup. $element[0] = $this->juicebox->buildEmbed($gallery, $this->getSettings(), $xml_route_info, $add_js, $this->isPseudoInstance(), $contextual); } catch (\Exception $e) { $message = 'Exception building Juicebox embed code for field: !message in %function (line %line of %file).'; watchdog_exception('juicebox', $e, $message); } return $element; }