Verified Commit c077be8a authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3421009 by sorlov, mohit_aghera, pradhumanjain2311, larowlan,...

Issue #3421009 by sorlov, mohit_aghera, pradhumanjain2311, larowlan, smustgrave, alexpott: Convert ViewsCache plugin discovery to attributes
parent 6e7fa7f3
Loading
Loading
Loading
Loading
+53 −0
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 cache plugins type attribute for plugin discovery.
 *
 * @see \Drupal\views\Plugin\views\cache\CachePluginBase
 *
 * @ingroup views_cache_plugins
 */
#[\Attribute(\Attribute::TARGET_CLASS)]
class ViewsCache extends Plugin {

  /**
   * Constructs a ViewsCache attribute.
   *
   * @param string $id
   *   The plugin ID.
   * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $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 $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
   *   The base tables on which this cache plugin can be used.
   *   If no base table is specified the plugin can be used with all tables.
   * @param bool $no_ui
   *   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.
   * @param class-string|null $deriver
   *   (optional) The deriver class.
   */
  public function __construct(
    public readonly string $id,
    public readonly ?TranslatableMarkup $title = NULL,
    public readonly ?TranslatableMarkup $short_title = NULL,
    public readonly ?TranslatableMarkup $help = NULL,
    public readonly ?array $display_types = NULL,
    public readonly array $base = [],
    public readonly ?bool $no_ui = NULL,
    public readonly ?string $deriver = NULL
  ) {}

}
+8 −6
Original line number Diff line number Diff line
@@ -2,17 +2,19 @@

namespace Drupal\views\Plugin\views\cache;

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

/**
 * Caching plugin that provides no caching at all.
 *
 * @ingroup views_cache_plugins
 *
 * @ViewsCache(
 *   id = "none",
 *   title = @Translation("None"),
 *   help = @Translation("No caching of Views data.")
 * )
 */
#[ViewsCache(
  id: 'none',
  title: new TranslatableMarkup('None'),
  help: new TranslatableMarkup('No caching of Views data.'),
)]
class None extends CachePluginBase {

  public function summaryTitle() {
+7 −6
Original line number Diff line number Diff line
@@ -3,18 +3,19 @@
namespace Drupal\views\Plugin\views\cache;

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsCache;

/**
 * Simple caching of query results for Views displays.
 *
 * @ingroup views_cache_plugins
 *
 * @ViewsCache(
 *   id = "tag",
 *   title = @Translation("Tag based"),
 *   help = @Translation("Tag based caching of data. Caches will persist until any related cache tags are invalidated.")
 * )
 */
#[ViewsCache(
  id: 'tag',
  title: new TranslatableMarkup('Tag based'),
  help: new TranslatableMarkup('Tag based caching of data. Caches will persist until any related cache tags are invalidated.'),
)]
class Tag extends CachePluginBase {

  /**
+7 −6
Original line number Diff line number Diff line
@@ -6,19 +6,20 @@
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsCache;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Simple caching of query results for Views displays.
 *
 * @ingroup views_cache_plugins
 *
 * @ViewsCache(
 *   id = "time",
 *   title = @Translation("Time-based"),
 *   help = @Translation("Simple time-based caching of data.")
 * )
 */
#[ViewsCache(
  id: 'time',
  title: new TranslatableMarkup('Time-based'),
  help: new TranslatableMarkup('Simple time-based caching of data.'),
)]
class Time extends CachePluginBase {

  /**