Issue #3421008 by el7cosmos, sorlov, smustgrave, larowlan, alexpott, quietone: Convert ViewsExposedForm plugin discovery to attributes

(cherry picked from commit 4586e9fc62)
merge-requests/6741/merge
Alex Pott 2024-03-13 11:36:11 +00:00
parent 0be35cacd6
commit 5d7c6f182a
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
3 changed files with 76 additions and 12 deletions

View File

@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Drupal\views\Attribute;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines a Plugin attribute object for views exposed form plugins.
*
* @see \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface
* @see \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase
*
* @ingroup views_exposed_form_plugins
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class ViewsExposedForm extends Plugin {
/**
* Constructs a views exposed form attribute object.
*
* @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 $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 exposed form 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 it's set to TRUE, you can still use it via the API in config files.
* Defaults to FALSE.
* @param bool $register_theme
* (optional) Whether to register a theme function automatically. Defaults
* to TRUE.
* @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 ?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
) {}
}

View File

@ -2,17 +2,19 @@
namespace Drupal\views\Plugin\views\exposed_form;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsExposedForm;
/**
* Exposed form plugin that provides a basic exposed form.
*
* @ingroup views_exposed_form_plugins
*
* @ViewsExposedForm(
* id = "basic",
* title = @Translation("Basic"),
* help = @Translation("Basic exposed form")
* )
*/
#[ViewsExposedForm(
id: 'basic',
title: new TranslatableMarkup('Basic'),
help: new TranslatableMarkup('Basic exposed form')
)]
class Basic extends ExposedFormPluginBase {
}

View File

@ -3,19 +3,20 @@
namespace Drupal\views\Plugin\views\exposed_form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsExposedForm;
use Drupal\views\Views;
/**
* Exposed form plugin that provides an exposed form with required input.
*
* @ingroup views_exposed_form_plugins
*
* @ViewsExposedForm(
* id = "input_required",
* title = @Translation("Input required"),
* help = @Translation("An exposed form that only renders a view if the form contains user input.")
* )
*/
#[ViewsExposedForm(
id: 'input_required',
title: new TranslatableMarkup('Input required'),
help: new TranslatableMarkup('An exposed form that only renders a view if the form contains user input.')
)]
class InputRequired extends ExposedFormPluginBase {
protected function defineOptions() {