Issue #3421002 by sorlov, Ruturaj Chaubey, smustgrave, larowlan: Convert ViewsDisplay plugin discovery to attributes
(cherry picked from commit a52189b391
)
merge-requests/7109/head
parent
498ce9e1a1
commit
cca3f394eb
|
@ -10,6 +10,8 @@ use Drupal\Core\Render\RenderContext;
|
|||
use Drupal\Core\Render\RendererInterface;
|
||||
use Drupal\Core\Routing\RouteProviderInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\views\Attribute\ViewsDisplay;
|
||||
use Drupal\views\Plugin\views\display\ResponseDisplayPluginInterface;
|
||||
use Drupal\views\Render\ViewsRenderPipelineMarkup;
|
||||
use Drupal\views\ViewExecutable;
|
||||
|
@ -22,16 +24,15 @@ use Symfony\Component\Routing\RouteCollection;
|
|||
* The plugin that handles Data response callbacks for REST resources.
|
||||
*
|
||||
* @ingroup views_display_plugins
|
||||
*
|
||||
* @ViewsDisplay(
|
||||
* id = "rest_export",
|
||||
* title = @Translation("REST export"),
|
||||
* help = @Translation("Create a REST export resource."),
|
||||
* uses_route = TRUE,
|
||||
* admin = @Translation("REST export"),
|
||||
* returns_response = TRUE
|
||||
* )
|
||||
*/
|
||||
#[ViewsDisplay(
|
||||
id: "rest_export",
|
||||
title: new TranslatableMarkup("REST export"),
|
||||
help: new TranslatableMarkup("Create a REST export resource."),
|
||||
admin: new TranslatableMarkup("REST export"),
|
||||
uses_route: TRUE,
|
||||
returns_response: TRUE
|
||||
)]
|
||||
class RestExport extends PathPluginBase implements ResponseDisplayPluginInterface {
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
<?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 display plugins.
|
||||
*
|
||||
* @see \Drupal\views\Plugin\views\display\DisplayPluginBase
|
||||
*
|
||||
* @ingroup views_display_plugins
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class ViewsDisplay extends Plugin {
|
||||
|
||||
/**
|
||||
* Constructs a views display 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 $admin
|
||||
* (optional) The administrative name of the display.
|
||||
* The name is displayed on the Views overview and also used as default name
|
||||
* for new displays.
|
||||
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $help
|
||||
* (optional) A short help string; this is displayed in the views UI.
|
||||
* @param bool $uses_menu_links
|
||||
* (optional) Whether or not to use hook_menu() to register a route.
|
||||
* Defaults to FALSE.
|
||||
* @param bool $uses_route
|
||||
* (optional) Does the display plugin registers routes to the route.
|
||||
* Defaults to FALSE.
|
||||
* @param bool $uses_hook_block
|
||||
* (optional) Does the display plugin provide blocks. Defaults to FALSE.
|
||||
* @param bool $returns_response
|
||||
* (optional) Whether the display returns a response object.
|
||||
* Defaults to FALSE.
|
||||
* @param string[]|null $contextual_links_locations
|
||||
* (optional) A list of places where contextual links should be added.
|
||||
* If you don't specify it there will be contextual links rendered for all
|
||||
* displays of a view. If this is not set or regions have been specified,
|
||||
* views will display an option to 'hide contextual links'. Use an empty
|
||||
* array to disable.
|
||||
* @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 string|null $theme
|
||||
* (optional) The theme function used to render the style output.
|
||||
* @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 bool $entity_reference_display
|
||||
* (optional) Custom property, used with \Drupal\views\Views::getApplicableViews().
|
||||
* Defaults to FALSE.
|
||||
* @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 $admin = NULL,
|
||||
public readonly ?TranslatableMarkup $help = NULL,
|
||||
public readonly bool $uses_menu_links = FALSE,
|
||||
public readonly bool $uses_route = FALSE,
|
||||
public readonly bool $uses_hook_block = FALSE,
|
||||
public readonly bool $returns_response = FALSE,
|
||||
public readonly ?array $contextual_links_locations = NULL,
|
||||
public readonly array $base = [],
|
||||
public readonly ?string $theme = NULL,
|
||||
public readonly bool $no_ui = FALSE,
|
||||
public readonly bool $register_theme = TRUE,
|
||||
public readonly bool $entity_reference_display = FALSE,
|
||||
public readonly ?string $deriver = NULL
|
||||
) {}
|
||||
|
||||
}
|
|
@ -3,6 +3,8 @@
|
|||
namespace Drupal\views\Plugin\views\display;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\views\Attribute\ViewsDisplay;
|
||||
use Drupal\views\ViewExecutable;
|
||||
|
||||
/**
|
||||
|
@ -13,15 +15,14 @@ use Drupal\views\ViewExecutable;
|
|||
* the same view. They can share some information.
|
||||
*
|
||||
* @ingroup views_display_plugins
|
||||
*
|
||||
* @ViewsDisplay(
|
||||
* id = "attachment",
|
||||
* title = @Translation("Attachment"),
|
||||
* help = @Translation("Attachments added to other displays to achieve multiple views in the same view."),
|
||||
* theme = "views_view",
|
||||
* contextual_links_locations = {""}
|
||||
* )
|
||||
*/
|
||||
#[ViewsDisplay(
|
||||
id: "attachment",
|
||||
title: new TranslatableMarkup("Attachment"),
|
||||
help: new TranslatableMarkup("Attachments added to other displays to achieve multiple views in the same view."),
|
||||
theme: "views_view",
|
||||
contextual_links_locations: [""]
|
||||
)]
|
||||
class Attachment extends DisplayPluginBase {
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,11 +3,13 @@
|
|||
namespace Drupal\views\Plugin\views\display;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
|
||||
use Drupal\Core\Block\BlockManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\views\Attribute\ViewsDisplay;
|
||||
use Drupal\views\Plugin\Block\ViewsBlock;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -16,20 +18,19 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
*
|
||||
* @ingroup views_display_plugins
|
||||
*
|
||||
* @ViewsDisplay(
|
||||
* id = "block",
|
||||
* title = @Translation("Block"),
|
||||
* help = @Translation("Display the view as a block."),
|
||||
* theme = "views_view",
|
||||
* register_theme = FALSE,
|
||||
* uses_hook_block = TRUE,
|
||||
* contextual_links_locations = {"block"},
|
||||
* admin = @Translation("Block")
|
||||
* )
|
||||
*
|
||||
* @see \Drupal\views\Plugin\Block\ViewsBlock
|
||||
* @see \Drupal\views\Plugin\Derivative\ViewsBlock
|
||||
*/
|
||||
#[ViewsDisplay(
|
||||
id: "block",
|
||||
title: new TranslatableMarkup("Block"),
|
||||
help: new TranslatableMarkup("Display the view as a block."),
|
||||
admin: new TranslatableMarkup("Block"),
|
||||
theme: "views_view",
|
||||
register_theme: FALSE,
|
||||
uses_hook_block: TRUE,
|
||||
contextual_links_locations: ["block"]
|
||||
)]
|
||||
class Block extends DisplayPluginBase {
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,19 +2,21 @@
|
|||
|
||||
namespace Drupal\views\Plugin\views\display;
|
||||
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\views\Attribute\ViewsDisplay;
|
||||
|
||||
/**
|
||||
* A plugin to handle defaults on a view.
|
||||
*
|
||||
* @ingroup views_display_plugins
|
||||
*
|
||||
* @ViewsDisplay(
|
||||
* id = "default",
|
||||
* title = @Translation("Default"),
|
||||
* help = @Translation("Default settings for this view."),
|
||||
* theme = "views_view",
|
||||
* no_ui = TRUE
|
||||
* )
|
||||
*/
|
||||
#[ViewsDisplay(
|
||||
id: "default",
|
||||
title: new TranslatableMarkup("Default"),
|
||||
help: new TranslatableMarkup("Default settings for this view."),
|
||||
theme: "views_view",
|
||||
no_ui: TRUE
|
||||
)]
|
||||
class DefaultDisplay extends DisplayPluginBase {
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Drupal\views\Plugin\views\display;
|
||||
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\views\Attribute\ViewsDisplay;
|
||||
|
||||
/**
|
||||
* The plugin that handles an embed display.
|
||||
*
|
||||
|
@ -9,15 +12,14 @@ namespace Drupal\views\Plugin\views\display;
|
|||
*
|
||||
* @todo: Wait until annotations/plugins support access methods.
|
||||
* no_ui => !\Drupal::config('views.settings')->get('ui.show.display_embed'),
|
||||
*
|
||||
* @ViewsDisplay(
|
||||
* id = "embed",
|
||||
* title = @Translation("Embed"),
|
||||
* help = @Translation("Provide a display which can be embedded using the views api."),
|
||||
* theme = "views_view",
|
||||
* uses_menu_links = FALSE
|
||||
* )
|
||||
*/
|
||||
#[ViewsDisplay(
|
||||
id: "embed",
|
||||
title: new TranslatableMarkup("Embed"),
|
||||
help: new TranslatableMarkup("Provide a display which can be embedded using the views api."),
|
||||
theme: "views_view",
|
||||
uses_menu_links: FALSE
|
||||
)]
|
||||
class Embed extends DisplayPluginBase {
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace Drupal\views\Plugin\views\display;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\views\Attribute\ViewsDisplay;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -13,18 +15,17 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
* 'Entity Reference' display.
|
||||
*
|
||||
* @ingroup views_display_plugins
|
||||
*
|
||||
* @ViewsDisplay(
|
||||
* id = "entity_reference",
|
||||
* title = @Translation("Entity Reference"),
|
||||
* admin = @Translation("Entity Reference Source"),
|
||||
* help = @Translation("Selects referenceable entities for an entity reference field."),
|
||||
* theme = "views_view",
|
||||
* register_theme = FALSE,
|
||||
* uses_menu_links = FALSE,
|
||||
* entity_reference_display = TRUE
|
||||
* )
|
||||
*/
|
||||
#[ViewsDisplay(
|
||||
id: "entity_reference",
|
||||
title: new TranslatableMarkup("Entity Reference"),
|
||||
admin: new TranslatableMarkup("Entity Reference Source"),
|
||||
help: new TranslatableMarkup("Selects referenceable entities for an entity reference field."),
|
||||
theme: "views_view",
|
||||
register_theme: FALSE,
|
||||
uses_menu_links: FALSE,
|
||||
entity_reference_display: TRUE
|
||||
)]
|
||||
class EntityReference extends DisplayPluginBase {
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,8 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
use Drupal\Core\Render\RendererInterface;
|
||||
use Drupal\Core\Routing\RouteProviderInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\views\Attribute\ViewsDisplay;
|
||||
use Drupal\views\ViewExecutable;
|
||||
use Drupal\views\Views;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -17,16 +19,15 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||
* The plugin that handles a feed, such as RSS or atom.
|
||||
*
|
||||
* @ingroup views_display_plugins
|
||||
*
|
||||
* @ViewsDisplay(
|
||||
* id = "feed",
|
||||
* title = @Translation("Feed"),
|
||||
* help = @Translation("Display the view as a feed, such as an RSS feed."),
|
||||
* uses_route = TRUE,
|
||||
* admin = @Translation("Feed"),
|
||||
* returns_response = TRUE
|
||||
* )
|
||||
*/
|
||||
#[ViewsDisplay(
|
||||
id: "feed",
|
||||
title: new TranslatableMarkup("Feed"),
|
||||
admin: new TranslatableMarkup("Feed"),
|
||||
help: new TranslatableMarkup("Display the view as a feed, such as an RSS feed."),
|
||||
uses_route: TRUE,
|
||||
returns_response: TRUE
|
||||
)]
|
||||
class Feed extends PathPluginBase implements ResponseDisplayPluginInterface {
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,8 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
use Drupal\Core\Menu\MenuParentFormSelectorInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\Core\Routing\RouteProviderInterface;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\views\Attribute\ViewsDisplay;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
|
@ -16,18 +18,17 @@ use Symfony\Component\Routing\Route;
|
|||
* The plugin that handles a full page.
|
||||
*
|
||||
* @ingroup views_display_plugins
|
||||
*
|
||||
* @ViewsDisplay(
|
||||
* id = "page",
|
||||
* title = @Translation("Page"),
|
||||
* help = @Translation("Display the view as a page, with a URL and menu links."),
|
||||
* uses_menu_links = TRUE,
|
||||
* uses_route = TRUE,
|
||||
* contextual_links_locations = {"page"},
|
||||
* theme = "views_view",
|
||||
* admin = @Translation("Page")
|
||||
* )
|
||||
*/
|
||||
#[ViewsDisplay(
|
||||
id: "page",
|
||||
title: new TranslatableMarkup("Page"),
|
||||
help: new TranslatableMarkup("Display the view as a page, with a URL and menu links."),
|
||||
uses_menu_links: TRUE,
|
||||
uses_route: TRUE,
|
||||
contextual_links_locations: ["page"],
|
||||
theme: "views_view",
|
||||
admin: new TranslatableMarkup("Page"),
|
||||
)]
|
||||
class Page extends PathPluginBase {
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,18 +2,20 @@
|
|||
|
||||
namespace Drupal\views_test_data\Plugin\views\display;
|
||||
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\views\Attribute\ViewsDisplay;
|
||||
|
||||
/**
|
||||
* Defines a Display test plugin with areas disabled.
|
||||
*
|
||||
* @ViewsDisplay(
|
||||
* id = "display_no_area_test",
|
||||
* title = @Translation("Display test no area"),
|
||||
* help = @Translation("Defines a display test with areas disabled."),
|
||||
* theme = "views_view",
|
||||
* register_theme = FALSE,
|
||||
* contextual_links_locations = {"view"}
|
||||
* )
|
||||
*/
|
||||
#[ViewsDisplay(
|
||||
id: "display_no_area_test",
|
||||
title: new TranslatableMarkup("Display test no area"),
|
||||
help: new TranslatableMarkup("Defines a display test with areas disabled."),
|
||||
theme: "views_view",
|
||||
register_theme: FALSE,
|
||||
contextual_links_locations: ["view"]
|
||||
)]
|
||||
class DisplayNoAreaTest extends DisplayTest {
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,20 +5,21 @@ namespace Drupal\views_test_data\Plugin\views\display;
|
|||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\views\Attribute\ViewsDisplay;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
|
||||
/**
|
||||
* Defines a Display test plugin.
|
||||
*
|
||||
* @ViewsDisplay(
|
||||
* id = "display_test",
|
||||
* title = @Translation("Display test"),
|
||||
* help = @Translation("Defines a display test plugin."),
|
||||
* theme = "views_view",
|
||||
* register_theme = FALSE,
|
||||
* contextual_links_locations = {"view"}
|
||||
* )
|
||||
*/
|
||||
#[ViewsDisplay(
|
||||
id: "display_test",
|
||||
title: new TranslatableMarkup("Display test"),
|
||||
help: new TranslatableMarkup("Defines a display test plugin."),
|
||||
theme: "views_view",
|
||||
register_theme: FALSE,
|
||||
contextual_links_locations: ["view"]
|
||||
)]
|
||||
class DisplayTest extends DisplayPluginBase {
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue