class JuiceboxXmlControllerViewsStyle in Juicebox HTML5 Responsive Image Galleries 8.3
Same name and namespace in other branches
- 8.2 src/Controller/JuiceboxXmlControllerViewsStyle.php \Drupal\juicebox\Controller\JuiceboxXmlControllerViewsStyle
Controller routines for field-based XML.
Hierarchy
- class \Drupal\juicebox\Controller\JuiceboxXmlControllerBase implements ContainerInjectionInterface
- class \Drupal\juicebox\Controller\JuiceboxXmlControllerViewsStyle
Expanded class hierarchy of JuiceboxXmlControllerViewsStyle
File
- src/
Controller/ JuiceboxXmlControllerViewsStyle.php, line 12
Namespace
Drupal\juicebox\ControllerView source
class JuiceboxXmlControllerViewsStyle extends JuiceboxXmlControllerBase {
/**
* The view machine name for the view involved in this XML request.
*
* @var string
*/
protected $viewName;
/**
* The view display name for the view involved in this XML request.
*
* @var string
*/
protected $displayName;
/**
* The loaded view involved in this XML request.
*
* @var \Drupal\views\ViewExecutable
*/
protected $view;
/**
* An indexed array of view args that apply to view used in this XML request.
*
* @var array
*/
protected $viewArgs = [];
/**
* {@inheritdoc}
*/
protected function init() {
$attribs = $this->request->attributes
->get('_raw_variables');
// Set data sources as properties.
$this->viewName = $attribs
->get('viewName');
$this->displayName = $attribs
->get('displayName');
$this->viewArgs = $this
->queryToArgs();
// Load the view itself.
$this->view = Views::getView($this->viewName);
if (is_object($this->view) && $this->view instanceof ViewExecutable) {
// All looks good.
return;
}
throw new \Exception('Cannot instantiate view-based Juicebox gallery as no view can be loaded.');
}
/**
* {@inheritdoc}
*/
protected function access() {
return $this->view
->access($this->displayName);
}
/**
* {@inheritdoc}
*/
protected function getGallery() {
$this->view
->setDisplay($this->displayName);
$this->view
->setArguments($this->viewArgs);
$rendered_view = $this->view
->render();
// Make sure that the Juicebox is actually built.
if (!empty($rendered_view['#rows']['#gallery']) && $rendered_view['#rows']['#gallery'] instanceof JuiceboxGalleryInterface && $rendered_view['#rows']['#gallery']
->getId()) {
return $rendered_view['#rows']['#gallery'];
}
throw new \Exception('Cannot build Juicebox XML for view-based gallery.');
}
/**
* {@inheritdoc}
*/
protected function calculateXmlCacheTags() {
// Pull the tags directly out of the view object.
return $this->view
->getCacheTags();
}
/**
* Utility to extract the current set of view args from query params.
*
* @return array
* A indexed array of the view args.
*/
protected function queryToArgs() {
$args = [];
// Get the args from the query params.
$query_args = $this->request->query
->all();
foreach ($query_args as $param => $value) {
if (preg_match('/^arg_[0-9]+$/', $param)) {
list(, $key) = explode('_', $param);
$args[$key] = $value;
}
}
return $args;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JuiceboxXmlControllerBase:: |
protected | property | An array for Drupal cache tags that applies to the page request. | |
JuiceboxXmlControllerBase:: |
protected | property | A Drupal configuration factory service. | |
JuiceboxXmlControllerBase:: |
protected | property | The Symfony http kernel service. | |
JuiceboxXmlControllerBase:: |
protected | property | A Symfony request object for the current request. | |
JuiceboxXmlControllerBase:: |
protected | property | The global Juicebox configuration. | |
JuiceboxXmlControllerBase:: |
public static | function |
Factory to fetch required dependencies from container. Overrides ContainerInjectionInterface:: |
1 |
JuiceboxXmlControllerBase:: |
protected | function | Attempt to fetch the gallery's XML via a sub-request to another page. | |
JuiceboxXmlControllerBase:: |
public | function | Common controller for the Juicebox XML. | |
JuiceboxXmlControllerBase:: |
public | function | Constructor. | 1 |
JuiceboxXmlControllerViewsStyle:: |
protected | property | The view display name for the view involved in this XML request. | |
JuiceboxXmlControllerViewsStyle:: |
protected | property | The loaded view involved in this XML request. | |
JuiceboxXmlControllerViewsStyle:: |
protected | property | An indexed array of view args that apply to view used in this XML request. | |
JuiceboxXmlControllerViewsStyle:: |
protected | property | The view machine name for the view involved in this XML request. | |
JuiceboxXmlControllerViewsStyle:: |
protected | function |
Check access to the Drupal data that will be used to build the gallery. Overrides JuiceboxXmlControllerBase:: |
|
JuiceboxXmlControllerViewsStyle:: |
protected | function |
Calculate any cache tags that should be applied to the XML. Overrides JuiceboxXmlControllerBase:: |
|
JuiceboxXmlControllerViewsStyle:: |
protected | function |
Get the Juicebox gallery object. Overrides JuiceboxXmlControllerBase:: |
|
JuiceboxXmlControllerViewsStyle:: |
protected | function |
Initialize the controller based on request data. Overrides JuiceboxXmlControllerBase:: |
|
JuiceboxXmlControllerViewsStyle:: |
protected | function | Utility to extract the current set of view args from query params. |