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

Issue #3421007 by sorlov, quietone, larowlan, smustgrave: Convert ViewsQuery...

Issue #3421007 by sorlov, quietone, larowlan, smustgrave: Convert ViewsQuery plugin discovery to attributes

(cherry picked from commit fb396fbd)
parent ee98c76b
Loading
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\views\Attribute;

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

/**
 * Defines a ViewsQuery attribute for plugin discovery.
 *
 * @see \Drupal\views\Plugin\views\query\QueryPluginBase
 *
 * @ingroup views_query_plugins
 */
#[\Attribute(\Attribute::TARGET_CLASS)]
class ViewsQuery extends Plugin {

  /**
   * Constructs an ViewsDisplayExtender 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
   *   A short help string; this is displayed in the views UI.
   * @param bool $no_ui
   *   Whether or not the plugin is selectable in the UI. If it's 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 bool $no_ui = FALSE,
    public readonly ?string $deriver = NULL
  ) {}

}
+7 −6
Original line number Diff line number Diff line
@@ -8,8 +8,10 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\views\Attribute\ViewsQuery;
use Drupal\views\Plugin\views\join\JoinPluginBase;
use Drupal\views\Plugin\views\HandlerBase;
use Drupal\views\ResultRow;
@@ -21,13 +23,12 @@
 * Views query plugin for an SQL query.
 *
 * @ingroup views_query_plugins
 *
 * @ViewsQuery(
 *   id = "views_query",
 *   title = @Translation("SQL Query"),
 *   help = @Translation("Query will be generated and run using the Drupal database API.")
 * )
 */
#[ViewsQuery(
  id: 'views_query',
  title: new TranslatableMarkup('SQL Query'),
  help: new TranslatableMarkup('Query will be generated and run using the Drupal database API.')
)]
class Sql extends QueryPluginBase {

  /**
+7 −6
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
namespace Drupal\views_test_data\Plugin\views\query;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsQuery;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\Plugin\views\join\JoinPluginBase;
use Drupal\views\ResultRow;
@@ -10,13 +12,12 @@

/**
 * Defines a query test plugin.
 *
 * @ViewsQuery(
 *   id = "query_test",
 *   title = @Translation("Query test"),
 *   help = @Translation("Defines a query test plugin.")
 * )
 */
#[ViewsQuery(
  id: 'query_test',
  title: new TranslatableMarkup('Query test'),
  help: new TranslatableMarkup('Defines a query test plugin.')
)]
class QueryTest extends QueryPluginBase {
  protected $conditions = [];
  protected $fields = [];