Verified Commit 0eca710d authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3421004 by Ruturaj Chaubey, sorlov, quietone, smustgrave, larowlan,...

Issue #3421004 by Ruturaj Chaubey, sorlov, quietone, smustgrave, larowlan, alexpott: Convert ViewsPager plugin discovery to attributes
parent 64de6a69
Loading
Loading
Loading
Loading
Loading
+60 −0
Changes for core/modules/views/src/Attribute/ViewsPager.php: 60 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\views\Attribute;

use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Defines a views pager plugins type attribute for plugin discovery.
 *
 * @see \Drupal\views\Plugin\views\pager\PagerPluginBase
 *
 * @ingroup views_pager_plugins
 */
#[\Attribute(\Attribute::TARGET_CLASS)]
class ViewsPager extends Plugin {

  /**
   * Constructs a ViewsPager attribute.
   *
   * @param string $id
   *   The plugin ID.
   * @param \Drupal\Core\StringTranslation\TranslatableMarkup $title
   *   The plugin title used in the views UI.
   * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $short_title
   *   (optional) The short title used in the views UI.
   * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $help
   *   (optional) A short help string; this is displayed in the views UI.
   * @param string|null $theme
   *   (optional) The theme function used to render the pager's output.
   * @param string[]|null $display_types
   *   (optional) The types of the display this plugin can be used with.
   *   For example the Feed display defines the type 'feed', so only rss style
   *   and row plugins can be used in the views UI.
   * @param string[] $base
   *   (optional) The base tables on which this access plugin can be used.
   *   If no base table is specified the plugin can be used with all tables.
   * @param bool $no_ui
   *   (optional) Whether the plugin should be not selectable in the UI.
   *   If set to TRUE, you can still use it via the API in config files.
   *   Defaults to FALSE.
   * @param bool $register_theme
   *   (optional) Whether or not to register a theme function automatically.
   * @param class-string|null $deriver
   *   (optional) The deriver class.
   */
  public function __construct(
    public readonly string $id,
    public readonly TranslatableMarkup $title,
    public readonly ?TranslatableMarkup $short_title = NULL,
    public readonly ?TranslatableMarkup $help = NULL,
    public readonly ?string $theme = NULL,
    public readonly ?array $display_types = NULL,
    public readonly array $base = [],
    public readonly bool $no_ui = FALSE,
    public readonly bool $register_theme = TRUE,
    public readonly ?string $deriver = NULL
  ) {}

}
+10 −9
Changes for core/modules/views/src/Plugin/views/pager/Full.php: 10 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -3,21 +3,22 @@
namespace Drupal\views\Plugin\views\pager;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsPager;

/**
 * The plugin to handle full pager.
 *
 * @ingroup views_pager_plugins
 *
 * @ViewsPager(
 *   id = "full",
 *   title = @Translation("Paged output, full pager"),
 *   short_title = @Translation("Full"),
 *   help = @Translation("Paged output, full Drupal style"),
 *   theme = "pager",
 *   register_theme = FALSE
 * )
 */
#[ViewsPager(
  id: "full",
  title: new TranslatableMarkup("Paged output, full pager"),
  short_title: new TranslatableMarkup("Full"),
  help: new TranslatableMarkup("Paged output, full Drupal style"),
  theme: "pager",
  register_theme: FALSE
)]
class Full extends SqlBase {

  /**
+12 −10
Changes for core/modules/views/src/Plugin/views/pager/Mini.php: 12 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -2,19 +2,21 @@

namespace Drupal\views\Plugin\views\pager;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsPager;

/**
 * The plugin to handle mini pager.
 *
 * @ingroup views_pager_plugins
 *
 * @ViewsPager(
 *   id = "mini",
 *   title = @Translation("Paged output, mini pager"),
 *   short_title = @Translation("Mini"),
 *   help = @Translation("A simple pager containing previous and next links."),
 *   theme = "views_mini_pager"
 * )
 */
#[ViewsPager(
  id: "mini",
  title: new TranslatableMarkup("Paged output, mini pager"),
  short_title: new TranslatableMarkup("Mini"),
  help: new TranslatableMarkup("A simple pager containing previous and next links."),
  theme: "views_mini_pager",
)]
class Mini extends SqlBase {

  /**
@@ -47,7 +49,7 @@ public function summaryTitle() {
  public function query() {
    parent::query();

    // Only modify the query if we don't want to do a total row count
    // Only modify the query if we don't want to do a total row count.
    if (!$this->view->get_total_rows) {
      // Don't query for the next page if we have a pager that has a limited
      // amount of pages.
@@ -72,7 +74,7 @@ public function useCountQuery() {
   * {@inheritdoc}
   */
  public function postExecute(&$result) {
    // Only modify the result if we didn't do a total row count
    // Only modify the result if we didn't do a total row count.
    if (!$this->view->get_total_rows) {
      $this->total_items = $this->getCurrentPage() * $this->getItemsPerPage() + count($result);
      // query() checks if we need a next link by setting limit 1 record past
+8 −7
Changes for core/modules/views/src/Plugin/views/pager/None.php: 8 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
namespace Drupal\views\Plugin\views\pager;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsPager;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;

@@ -10,14 +12,13 @@
 * Plugin for views without pagers.
 *
 * @ingroup views_pager_plugins
 *
 * @ViewsPager(
 *   id = "none",
 *   title = @Translation("Display all items"),
 *   help = @Translation("Display all items that this view might find."),
 *   display_types = {"basic"}
 * )
 */
#[ViewsPager(
  id: "none",
  title: new TranslatableMarkup("Display all items"),
  help: new TranslatableMarkup("Display all items that this view might find."),
  display_types: ["basic"],
)]
class None extends PagerPluginBase {

  /**
+1 −1
Changes for core/modules/views/src/Plugin/views/pager/PagerPluginBase.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
 * and setting up the pager.
 *
 * Pager plugins extend \Drupal\views\Plugin\views\pager\PagerPluginBase. They
 * must be annotated with \Drupal\views\Annotation\ViewsPager annotation,
 * must be attributed with \Drupal\views\Annotation\ViewsPager attribute,
 * and they must be in namespace directory Plugin\views\pager.
 *
 * @ingroup views_plugins
Loading