You are here

protected function Mini::buildPagerItems in Pagerer 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/pagerer/Mini.php \Drupal\pagerer\Plugin\pagerer\Mini::buildPagerItems()

Return the pager render array.

Return value

array render array.

File

src/Plugin/pagerer/Mini.php, line 82

Class

Mini
Pager style to display current page/item in a direct entry textbox.

Namespace

Drupal\pagerer\Plugin\pagerer

Code

protected function buildPagerItems() {

  // Return immediately if configuration is not set to display the page
  // widget.
  if ($this
    ->getOption('display_mode') != 'widget') {
    return [];
  }

  // Prepares state.
  $state_settings = [
    'widgetResize' => $this
      ->getOption('widget_resize'),
    'widgetButton' => $this
      ->getOption('widget_button'),
  ];
  $pagerer_widget_id = $this
    ->prepareJsState($state_settings);

  // Entry textbox.
  return [
    [
      'widget' => [
        '#theme' => 'pagerer_mini',
        '#id' => $pagerer_widget_id,
        '#title' => $this
          ->getDisplayTag('widget_title'),
        '#value' => $state_settings['value'],
        '#min' => 1,
        '#max' => $this
          ->getOption('display') == 'pages' ? $state_settings['total'] : $state_settings['totalItems'],
        '#step' => $state_settings['interval'],
        '#button' => $this
          ->getOption('widget_button') === 'no' ? FALSE : TRUE,
        '#attached' => [
          'drupalSettings' => [
            'pagerer' => [
              'state' => [
                $pagerer_widget_id => $state_settings,
              ],
            ],
          ],
        ],
      ],
    ],
  ];
}