You are here

class PagererExampleController in Pagerer 8

Same name and namespace in other branches
  1. 8.2 pagerer_example/src/Controller/PagererExampleController.php \Drupal\pagerer_example\Controller\PagererExampleController

Controller class for Pagerer example.

Hierarchy

Expanded class hierarchy of PagererExampleController

File

pagerer_example/src/Controller/PagererExampleController.php, line 10

Namespace

Drupal\pagerer_example\Controller
View source
class PagererExampleController extends ControllerBase {

  /**
   * Get pagerer example page title.
   *
   * @return string
   *   The page title.
   */
  public function examplePageTitle() {

    // Set the page title to show current Pagerer version.
    $module_info = system_get_info('module', 'pagerer');
    return $this
      ->t("Pagerer @version - example page", [
      '@version' => $module_info['version'],
    ]);
  }

  /**
   * Build the pagerer example page.
   *
   * @return array
   *   A render array.
   */
  public function examplePage() {

    // First data table - associated to pager element 0.
    $header_0 = [
      [
        'data' => 'wid',
      ],
      [
        'data' => 'type',
      ],
      [
        'data' => 'timestamp',
      ],
    ];
    $query_0 = \Drupal::database()
      ->select('watchdog', 'd')
      ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
      ->element(0);
    $result_0 = $query_0
      ->fields('d', [
      'wid',
      'type',
      'timestamp',
    ])
      ->limit(5)
      ->orderBy('d.wid')
      ->execute();
    $rows_0 = [];
    foreach ($result_0 as $row) {
      $rows_0[] = [
        'data' => (array) $row,
      ];
    }

    // Second data table - associated to pager element 1.
    $header_1 = [
      [
        'data' => 'collection',
      ],
      [
        'data' => 'name',
      ],
    ];
    $query_1 = \Drupal::database()
      ->select('key_value', 'd')
      ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
      ->element(1);
    $result_1 = $query_1
      ->fields('d', [
      'collection',
      'name',
    ])
      ->limit(10)
      ->orderBy('d.collection')
      ->orderBy('d.name')
      ->execute();
    $rows_1 = [];
    foreach ($result_1 as $row) {
      $rows_1[] = [
        'data' => (array) $row,
      ];
    }

    // Third data table - associated to pager element 2.
    $header_2 = [
      [
        'data' => 'name',
      ],
      [
        'data' => 'path',
      ],
    ];
    $query_2 = \Drupal::database()
      ->select('router', 'd')
      ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
      ->element(2);
    $result_2 = $query_2
      ->fields('d', [
      'name',
      'path',
    ])
      ->limit(5)
      ->orderBy('d.name')
      ->execute();
    $rows_2 = [];
    foreach ($result_2 as $row) {
      $rows_2[] = [
        'data' => (array) $row,
      ];
    }

    // Create a render array ($build) which will be themed for output.
    $build = [];

    // Some description.
    $build['initdesc'] = [
      '#markup' => $this
        ->t("This page is an example of pagerer's features. It runs three separate queries on the database, and renders three tables with the results. A distinct pager is associated to each of the tables, and each pager is rendered through various pagerer's styles.") . '<p/><hr/>',
    ];

    // First table.
    $build['l_pager_table_0'] = [
      '#markup' => '<br/><br/><h2><b>' . $this
        ->t("First data table:") . '</b></h2>',
    ];
    $build['pager_table_0'] = [
      '#theme' => 'table',
      '#header' => $header_0,
      '#rows' => $rows_0,
      '#empty' => $this
        ->t("There are no watchdog records found in the db"),
    ];

    // Attach the pager themes.
    $build['l_pager_pager_0'] = [
      '#markup' => '<b>' . $this
        ->t("Drupal standard 'pager' theme:") . '</b>',
    ];
    $build['pager_pager_0'] = [
      '#type' => 'pager',
      '#theme' => 'pager',
      '#element' => 0,
    ];
    $build['l_pagerer_standard_0'] = [
      '#markup' => '<br/>' . $this
        ->t("<b>'Standard' pagerer style (mimick of Drupal's standard)</b> in three 'display' modes: 'pages', 'items', and 'item_ranges'"),
    ];
    $build['pagerer_standard_pages_0'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer_base',
      '#element' => 0,
      '#style' => 'standard',
      '#config' => [
        'display_restriction' => 0,
      ],
    ];
    $build['pagerer_standard_items_0'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer_base',
      '#element' => 0,
      '#style' => 'standard',
      '#config' => [
        'display_restriction' => 0,
        'display' => 'items',
      ],
    ];
    $build['pagerer_standard_item_ranges_0'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer_base',
      '#element' => 0,
      '#style' => 'standard',
      '#config' => [
        'display_restriction' => 0,
        'display' => 'item_ranges',
      ],
    ];
    $build['l_pagerer_progressive_0'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'Progressive' pagerer style:") . '</b>',
    ];
    $build['pagerer_progressive_0'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer_base',
      '#element' => 0,
      '#style' => 'progressive',
      '#config' => [
        'display_restriction' => 0,
      ],
    ];
    $build['l_pagerer_adaptive_0'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'Adaptive' pagerer style:") . '</b>',
    ];
    $build['pagerer_adaptive_0'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer_base',
      '#element' => 0,
      '#style' => 'adaptive',
      '#config' => [
        'display_restriction' => 0,
      ],
    ];
    $build['l_pagerer_mini_0'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'Mini' pagerer style:") . '</b>',
    ];
    $build['pagerer_mini_0'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer_base',
      '#element' => 0,
      '#style' => 'mini',
      '#config' => [
        'display_restriction' => 0,
      ],
    ];
    $build['l_pagerer_scrollpane_0'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'Scrollpane' pagerer style:") . '</b>',
    ];
    $build['pagerer_scrollpane_0'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer_base',
      '#element' => 0,
      '#style' => 'scrollpane',
      '#config' => [
        'display_restriction' => 0,
      ],
    ];
    $build['l_pagerer_slider_0'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'Slider' pagerer style:") . '</b>',
    ];
    $build['pagerer_slider_0'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer_base',
      '#element' => 0,
      '#style' => 'slider',
      '#config' => [
        'display_restriction' => 0,
      ],
    ];
    $build['l_pagerer_pagerer_0'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'pagerer' core replacement theme:") . '</b>',
    ];
    $build['pagerer_pagerer_0'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer',
      '#element' => 0,
      '#config' => [
        'preset' => $this
          ->config('pagerer.settings')
          ->get('core_override_preset'),
      ],
    ];
    $build['end_table_0'] = [
      '#markup' => '<p/><hr/>',
    ];

    // Second table.
    $build['l_pager_table_1'] = [
      '#markup' => '<br/><br/><h2><b>' . $this
        ->t("Second data table:") . '</b></h2>',
    ];
    $build['pager_table_1'] = [
      '#theme' => 'table',
      '#header' => $header_1,
      '#rows' => $rows_1,
      '#empty' => $this
        ->t("There are no date formats found in the db"),
    ];

    // Attach the pager themes.
    $build['l_pagerer_basic_1'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'Basic' pagerer style:") . '</b>',
    ];
    $build['pagerer_basic_1'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer_base',
      '#element' => 1,
      '#style' => 'basic',
      '#config' => [
        'display_restriction' => 0,
      ],
    ];
    $build['l_pagerer_adaptive_1'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'Adaptive' pagerer style:") . '</b>',
    ];
    $build['pagerer_adaptive_1'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer_base',
      '#element' => 1,
      '#style' => 'adaptive',
      '#config' => [
        'display_restriction' => 0,
      ],
    ];
    $build['l_pagerer_pagerer_1'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'pagerer' core replacement theme:") . '</b>',
    ];
    $build['pagerer_pagerer_1'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer',
      '#element' => 1,
      '#config' => [
        'preset' => $this
          ->config('pagerer.settings')
          ->get('core_override_preset'),
      ],
    ];
    $build['l_pagerer_pagerer_direct_1'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'pagerer' (direct call from module) theme:") . '</b> ' . $this
        ->t("Note the usage of the 'tags' variables to customise labels and hover titles."),
    ];
    $build['pagerer_pagerer_direct_1'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer',
      '#element' => 1,
      '#config' => [
        'panes' => [
          'left' => [
            'style' => 'mini',
            'config' => [
              'tags' => [
                'items' => [
                  'first_title' => $this
                    ->t("Go to the beginning of the recordset"),
                  'previous_title' => $this
                    ->t("Go to the previous range of records"),
                ],
              ],
              'display' => 'items',
              'display_mode' => 'none',
              'prefix_display' => FALSE,
              'suffix_display' => FALSE,
              'first_link' => 'always',
              'previous_link' => 'always',
              'next_link' => 'never',
              'last_link' => 'never',
            ],
          ],
          'center' => [
            'style' => 'mini',
            'config' => [
              'tags' => [
                'items' => [
                  'prefix_label' => $this
                    ->t("Record"),
                  'widget_title' => $this
                    ->t("Enter record and press Return. Up/Down arrow keys are enabled."),
                ],
              ],
              'display_restriction' => 0,
              'display' => 'items',
              'display_mode' => 'widget',
              'prefix_display' => TRUE,
              'suffix_display' => TRUE,
              'first_link' => 'never',
              'previous_link' => 'never',
              'next_link' => 'never',
              'last_link' => 'never',
            ],
          ],
          'right' => [
            'style' => 'mini',
            'config' => [
              'tags' => [
                'items' => [
                  'next_title' => $this
                    ->t("Go to the next range of records"),
                  'last_title' => $this
                    ->t("Go to the end of the recordset"),
                ],
              ],
              'display' => 'items',
              'display_mode' => 'none',
              'prefix_display' => FALSE,
              'suffix_display' => FALSE,
              'first_link' => 'never',
              'previous_link' => 'never',
              'next_link' => 'always',
              'last_link' => 'always',
            ],
          ],
        ],
      ],
    ];
    $build['end_table_1'] = [
      '#markup' => '<p/><hr/>',
    ];

    // Third table.
    $build['l_pager_table_2'] = [
      '#markup' => '<br/><br/><h2><b>' . $this
        ->t("Third data table:") . '</b></h2>',
    ];
    $build['pager_table_2'] = [
      '#theme' => 'table',
      '#header' => $header_2,
      '#rows' => $rows_2,
      '#empty' => $this
        ->t("There are no routes found in the db"),
    ];

    // Attach the pager themes.
    $build['l_pagerer_adaptive_2'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'Adaptive' pagerer style:") . '</b>',
    ];
    $build['pagerer_adaptive_2'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer_base',
      '#element' => 2,
      '#style' => 'adaptive',
      '#config' => [
        'display_restriction' => 0,
      ],
    ];
    $build['l_pagerer_pagerer_2'] = [
      '#markup' => '<br/><b>' . $this
        ->t("'pagerer' core replacement theme:") . '</b>',
    ];
    $build['pagerer_pagerer_2'] = [
      '#type' => 'pager',
      '#theme' => 'pagerer',
      '#element' => 2,
      '#config' => [
        'preset' => $this
          ->config('pagerer.settings')
          ->get('core_override_preset'),
      ],
    ];
    $build['end_table_2'] = [
      '#markup' => '<p/><hr/>',
    ];
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ControllerBase::$configFactory protected property The configuration factory.
ControllerBase::$currentUser protected property The current user service. 1
ControllerBase::$entityFormBuilder protected property The entity form builder.
ControllerBase::$entityManager protected property The entity manager.
ControllerBase::$entityTypeManager protected property The entity type manager.
ControllerBase::$formBuilder protected property The form builder. 2
ControllerBase::$keyValue protected property The key-value storage. 1
ControllerBase::$languageManager protected property The language manager. 1
ControllerBase::$moduleHandler protected property The module handler. 2
ControllerBase::$stateService protected property The state service.
ControllerBase::cache protected function Returns the requested cache bin.
ControllerBase::config protected function Retrieves a configuration object.
ControllerBase::container private function Returns the service container.
ControllerBase::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create 40
ControllerBase::currentUser protected function Returns the current user. 1
ControllerBase::entityFormBuilder protected function Retrieves the entity form builder.
ControllerBase::entityManager Deprecated protected function Retrieves the entity manager service.
ControllerBase::entityTypeManager protected function Retrieves the entity type manager.
ControllerBase::formBuilder protected function Returns the form builder service. 2
ControllerBase::keyValue protected function Returns a key/value storage collection. 1
ControllerBase::languageManager protected function Returns the language manager service. 1
ControllerBase::moduleHandler protected function Returns the module handler. 2
ControllerBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
ControllerBase::state protected function Returns the state storage service.
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PagererExampleController::examplePage public function Build the pagerer example page.
PagererExampleController::examplePageTitle public function Get pagerer example page title.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.