Issue #3421005 by Ruturaj Chaubey, sorlov, quietone, smustgrave, larowlan, alexpott: Convert ViewsStyle plugin discovery to attributes

(cherry picked from commit f944f4886c)
merge-requests/7287/head
Alex Pott 2024-03-27 15:32:30 +00:00
parent dd091490e5
commit a28538b0ab
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
15 changed files with 190 additions and 113 deletions

View File

@ -5,6 +5,8 @@ namespace Drupal\rest\Plugin\views\style;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
use Drupal\views\Plugin\views\style\StylePluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Serializer\SerializerInterface;
@ -13,14 +15,13 @@ use Symfony\Component\Serializer\SerializerInterface;
* The style plugin for serialized output formats.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "serializer",
* title = @Translation("Serializer"),
* help = @Translation("Serializes views row data using the Serializer component."),
* display_types = {"data"}
* )
*/
#[ViewsStyle(
id: "serializer",
title: new TranslatableMarkup("Serializer"),
help: new TranslatableMarkup("Serializes views row data using the Serializer component."),
display_types: ["data"],
)]
class Serializer extends StylePluginBase implements CacheableDependencyInterface {
/**

View File

@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace Drupal\views\Attribute;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines a views style plugins type attribute for plugin discovery.
*
* @see \Drupal\views\Plugin\views\style\StylePluginBase
*
* @ingroup views_style_plugins
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class ViewsStyle extends Plugin {
/**
* Constructs a ViewsStyle 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 $theme
* (optional) The theme function used to render the style output.
* @param string[] $display_types
* 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 = [],
public readonly array $base = [],
public readonly bool $no_ui = FALSE,
public readonly bool $register_theme = TRUE,
public readonly ?string $deriver = NULL
) {}
}

View File

@ -2,21 +2,23 @@
namespace Drupal\views\Plugin\views\style;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
/**
* Unformatted style plugin to render rows.
*
* Row are rendered one after another with no decorations.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "default",
* title = @Translation("Unformatted list"),
* help = @Translation("Displays rows one after another."),
* theme = "views_view_unformatted",
* display_types = {"normal"}
* )
*/
#[ViewsStyle(
id: "default",
title: new TranslatableMarkup("Unformatted list"),
help: new TranslatableMarkup("Displays rows one after another."),
theme: "views_view_unformatted",
display_types: ["normal"],
)]
class DefaultStyle extends StylePluginBase {
/**

View File

@ -3,20 +3,21 @@
namespace Drupal\views\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
/**
* The default style plugin for summaries.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "default_summary",
* title = @Translation("List"),
* help = @Translation("Displays the default summary as a list."),
* theme = "views_view_summary",
* display_types = {"summary"}
* )
*/
#[ViewsStyle(
id: "default_summary",
title: new TranslatableMarkup("List"),
help: new TranslatableMarkup("Displays the default summary as a list."),
theme: "views_view_summary",
display_types: ["summary"],
)]
class DefaultSummary extends StylePluginBase {
protected function defineOptions() {

View File

@ -4,21 +4,22 @@ namespace Drupal\views\Plugin\views\style;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
/**
* EntityReference style plugin.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "entity_reference",
* title = @Translation("Entity Reference list"),
* help = @Translation("Returns results as a PHP array of labels and rendered rows."),
* theme = "views_view_unformatted",
* register_theme = FALSE,
* display_types = {"entity_reference"}
* )
*/
#[ViewsStyle(
id: "entity_reference",
title: new TranslatableMarkup("Entity Reference list"),
help: new TranslatableMarkup("Returns results as a PHP array of labels and rendered rows."),
theme: "views_view_unformatted",
register_theme: FALSE,
display_types: ["entity_reference"],
)]
class EntityReference extends StylePluginBase {
/**

View File

@ -4,20 +4,21 @@ namespace Drupal\views\Plugin\views\style;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
/**
* Style plugin to render each item in a grid cell.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "grid",
* title = @Translation("Grid"),
* help = @Translation("Displays rows in a grid."),
* theme = "views_view_grid",
* display_types = {"normal"}
* )
*/
#[ViewsStyle(
id: "grid",
title: new TranslatableMarkup("Grid"),
help: new TranslatableMarkup("Displays rows in a grid."),
theme: "views_view_grid",
display_types: ["normal"],
)]
class Grid extends StylePluginBase {
/**

View File

@ -3,20 +3,21 @@
namespace Drupal\views\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
/**
* Style plugin to render each item in a responsive grid cell.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "grid_responsive",
* title = @Translation("Responsive Grid"),
* help = @Translation("Displays rows in a responsive grid."),
* theme = "views_view_grid_responsive",
* display_types = {"normal"}
* )
*/
#[ViewsStyle(
id: "grid_responsive",
title: new TranslatableMarkup("Responsive Grid"),
help: new TranslatableMarkup("Displays rows in a responsive grid."),
theme: "views_view_grid_responsive",
display_types: ["normal"],
)]
class GridResponsive extends StylePluginBase {
/**

View File

@ -3,20 +3,21 @@
namespace Drupal\views\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
/**
* Style plugin to render each item in an ordered or unordered list.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "html_list",
* title = @Translation("HTML List"),
* help = @Translation("Displays rows as HTML list."),
* theme = "views_view_list",
* display_types = {"normal"}
* )
*/
#[ViewsStyle(
id: "html_list",
title: new TranslatableMarkup("HTML List"),
help: new TranslatableMarkup("Displays rows as HTML list."),
theme: "views_view_list",
display_types: ["normal"],
)]
class HtmlList extends StylePluginBase {
/**

View File

@ -2,21 +2,22 @@
namespace Drupal\views\Plugin\views\style;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Drupal\views\Attribute\ViewsStyle;
/**
* Default style plugin to render an OPML feed.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "opml",
* title = @Translation("OPML Feed"),
* help = @Translation("Generates an OPML feed from a view."),
* theme = "views_view_opml",
* display_types = {"feed"}
* )
*/
#[ViewsStyle(
id: "opml",
title: new TranslatableMarkup("OPML Feed"),
help: new TranslatableMarkup("Generates an OPML feed from a view."),
theme: "views_view_opml",
display_types: ["feed"],
)]
class Opml extends StylePluginBase {
/**

View File

@ -3,21 +3,22 @@
namespace Drupal\views\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Drupal\views\Attribute\ViewsStyle;
/**
* Default style plugin to render an RSS feed.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "rss",
* title = @Translation("RSS Feed"),
* help = @Translation("Generates an RSS feed from a view."),
* theme = "views_view_rss",
* display_types = {"feed"}
* )
*/
#[ViewsStyle(
id: "rss",
title: new TranslatableMarkup("RSS Feed"),
help: new TranslatableMarkup("Generates an RSS feed from a view."),
theme: "views_view_rss",
display_types: ["feed"],
)]
class Rss extends StylePluginBase {
/**

View File

@ -6,21 +6,22 @@ use Drupal\Component\Utility\Html;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
use Drupal\views\Plugin\views\wizard\WizardInterface;
/**
* Style plugin to render each item as a row in a table.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "table",
* title = @Translation("Table"),
* help = @Translation("Displays rows in a table."),
* theme = "views_view_table",
* display_types = {"normal"}
* )
*/
#[ViewsStyle(
id: "table",
title: new TranslatableMarkup("Table"),
help: new TranslatableMarkup("Displays rows in a table."),
theme: "views_view_table",
display_types: ["normal"],
)]
class Table extends StylePluginBase implements CacheableDependencyInterface {
/**

View File

@ -3,20 +3,21 @@
namespace Drupal\views\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
/**
* The default style plugin for summaries.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "unformatted_summary",
* title = @Translation("Unformatted"),
* help = @Translation("Displays the summary unformatted, with option for one after another or inline."),
* theme = "views_view_summary_unformatted",
* display_types = {"summary"}
* )
*/
#[ViewsStyle(
id: "unformatted_summary",
title: new TranslatableMarkup("Unformatted"),
help: new TranslatableMarkup("Displays the summary unformatted, with option for one after another or inline."),
theme: "views_view_summary_unformatted",
display_types: ["summary"],
)]
class UnformattedSummary extends DefaultSummary {
protected function defineOptions() {

View File

@ -2,6 +2,8 @@
namespace Drupal\views_test_data\Plugin\views\style;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
use Drupal\views\Plugin\views\style\Mapping;
use Drupal\views\Plugin\views\field\NumericField;
@ -9,15 +11,14 @@ use Drupal\views\Plugin\views\field\NumericField;
* Provides a test plugin for the mapping style.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "mapping_test",
* title = @Translation("Field mapping"),
* help = @Translation("Maps specific fields to specific purposes."),
* theme = "views_view_mapping_test",
* display_types = {"normal", "test"}
* )
*/
#[ViewsStyle(
id: "mapping_test",
title: new TranslatableMarkup("Field mapping"),
help: new TranslatableMarkup("Maps specific fields to specific purposes."),
theme: "views_view_mapping_test",
display_types: ["normal", "test"],
)]
class MappingTest extends Mapping {
/**

View File

@ -2,21 +2,22 @@
namespace Drupal\views_test_data\Plugin\views\style;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
use Drupal\views\Plugin\views\style\StylePluginBase;
/**
* Provides a general test style template plugin.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "test_template_style",
* title = @Translation("Test style template plugin"),
* help = @Translation("Provides a generic style template test plugin."),
* theme = "views_view_style_template_test",
* display_types = {"normal", "test"}
* )
*/
#[ViewsStyle(
id: "test_template_style",
title: new TranslatableMarkup("Test style template plugin"),
help: new TranslatableMarkup("Provides a generic style template test plugin."),
theme: "views_view_style_template_test",
display_types: ["normal", "test"],
)]
class StyleTemplateTest extends StylePluginBase {
/**

View File

@ -3,22 +3,23 @@
namespace Drupal\views_test_data\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
use Drupal\views\Plugin\views\style\StylePluginBase;
/**
* Provides a general test style plugin.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "test_style",
* title = @Translation("Test style plugin"),
* help = @Translation("Provides a generic style test plugin."),
* theme = "views_view_style_test",
* register_theme = FALSE,
* display_types = {"normal", "test"}
* )
*/
#[ViewsStyle(
id: "test_style",
title: new TranslatableMarkup("Test style plugin"),
help: new TranslatableMarkup("Provides a generic style test plugin."),
theme: "views_view_style_test",
register_theme: FALSE,
display_types: ["normal", "test"],
)]
class StyleTest extends StylePluginBase {
/**