Multipane.php in Pagerer 8.2
File
src/Plugin/pagerer/Multipane.php
View source
<?php
namespace Drupal\pagerer\Plugin\pagerer;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Plugin\PluginBase;
use Drupal\pagerer\Pagerer;
use Drupal\pagerer\Entity\PagererPreset;
use Drupal\pagerer\Plugin\PagererStyleInterface;
class Multipane extends PluginBase implements PagererStyleInterface {
protected $pager;
public function setPager(Pagerer $pager) {
$this->pager = $pager;
return $this;
}
public function preprocess(array &$variables) {
if (!empty($this->configuration['preset'])) {
$preset = PagererPreset::load($this->configuration['preset']);
}
if (isset($preset)) {
$cacheable = TRUE;
foreach ([
'left',
'center',
'right',
] as $pane) {
if ($preset_style = $preset
->getPaneData($pane, 'style')) {
$this->configuration['panes'][$pane]['style'] = $preset_style;
}
if (!empty($this->configuration['panes'][$pane]['config'])) {
$cacheable = FALSE;
}
if ($preset_config = $preset
->getPaneData($pane, 'config')) {
$this->configuration['panes'][$pane]['config'] = NestedArray::mergeDeep($preset_config, $this->configuration['panes'][$pane]['config']);
}
}
}
$page_restriction = min(isset($this->configuration['panes']['left']['config']['display_restriction']) ? $this->configuration['panes']['left']['config']['display_restriction'] : 2, isset($this->configuration['panes']['center']['config']['display_restriction']) ? $this->configuration['panes']['center']['config']['display_restriction'] : 2, isset($this->configuration['panes']['right']['config']['display_restriction']) ? $this->configuration['panes']['right']['config']['display_restriction'] : 2);
if ($this->pager
->getTotalPages() < $page_restriction) {
return;
}
foreach ([
'left',
'center',
'right',
] as $pane) {
if ($this->configuration['panes'][$pane]['style'] != 'none') {
$variables['pagerer'][$pane . '_pane'] = [
'#type' => 'pager',
'#theme' => 'pagerer_base',
'#style' => $this->configuration['panes'][$pane]['style'],
'#route_name' => $variables['pager']['#route_name'],
'#route_parameters' => isset($variables['pager']['#route_parameters']) ? $variables['pager']['#route_parameters'] : [],
'#element' => $variables['pager']['#element'],
'#parameters' => $variables['pager']['#parameters'],
'#config' => $this->configuration['panes'][$pane]['config'],
];
}
else {
$variables['pagerer'][$pane . '_pane'] = [];
}
}
if (isset($preset) && $cacheable) {
CacheableMetadata::createFromRenderArray($variables)
->merge(CacheableMetadata::createFromObject($preset))
->applyTo($variables);
}
}
}
Classes
Name |
Description |
Multipane |
A multi-pane (left, center, and right) pager style. |