Skip to content
Snippets Groups Projects
Commit 320e5fd6 authored by catch's avatar catch
Browse files

Issue #3421006 by godotislate, Ruturaj Chaubey, larowlan, longwave,...

Issue #3421006 by godotislate, Ruturaj Chaubey, larowlan, longwave, smustgrave: Convert ViewsDisplayExtender plugin discovery to attributes
parent b46fb5e6
No related branches found
No related tags found
No related merge requests found
<?php
namespace Drupal\views\Attribute;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines a Plugin attribute object for views display extender plugins.
*
* @see \Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase
*
* @ingroup views_display_extender_plugins
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class ViewsDisplayExtender 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 the plugin is selectable in the UI.
* @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
) {}
}
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\views\Plugin; namespace Drupal\views\Plugin;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Plugin\DefaultPluginManager;
...@@ -21,7 +22,7 @@ class ViewsPluginManager extends DefaultPluginManager { ...@@ -21,7 +22,7 @@ class ViewsPluginManager extends DefaultPluginManager {
* The plugin type, for example filter. * The plugin type, for example filter.
* @param \Traversable $namespaces * @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths * An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations, * keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use. * Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
...@@ -29,7 +30,10 @@ class ViewsPluginManager extends DefaultPluginManager { ...@@ -29,7 +30,10 @@ class ViewsPluginManager extends DefaultPluginManager {
*/ */
public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
$plugin_definition_annotation_name = 'Drupal\views\Annotation\Views' . Container::camelize($type); $plugin_definition_annotation_name = 'Drupal\views\Annotation\Views' . Container::camelize($type);
parent::__construct("Plugin/views/$type", $namespaces, $module_handler, 'Drupal\views\Plugin\views\ViewsPluginInterface', $plugin_definition_annotation_name); // Special handling until all views plugins have attribute classes.
$attribute_name_candidate = 'Drupal\views\Attribute\Views' . Container::camelize($type);
$plugin_definition_attribute_name = class_exists($attribute_name_candidate) ? $attribute_name_candidate : Plugin::class;
parent::__construct("Plugin/views/$type", $namespaces, $module_handler, 'Drupal\views\Plugin\views\ViewsPluginInterface', $plugin_definition_attribute_name, $plugin_definition_annotation_name);
$this->defaults += [ $this->defaults += [
'parent' => 'parent', 'parent' => 'parent',
......
...@@ -2,18 +2,20 @@ ...@@ -2,18 +2,20 @@
namespace Drupal\views\Plugin\views\display_extender; namespace Drupal\views\Plugin\views\display_extender;
use Drupal\views\Attribute\ViewsDisplayExtender;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/** /**
* Default display extender plugin; does nothing. * Default display extender plugin; does nothing.
* *
* @ingroup views_display_extender_plugins * @ingroup views_display_extender_plugins
*
* @ViewsDisplayExtender(
* id = "default",
* title = @Translation("Empty display extender"),
* help = @Translation("Default settings for this view."),
* no_ui = TRUE
* )
*/ */
#[ViewsDisplayExtender(
id: 'default',
title: new TranslatableMarkup('Empty display extender'),
help: new TranslatableMarkup('Default settings for this view.'),
no_ui: TRUE
)]
class DefaultDisplayExtender extends DisplayExtenderPluginBase { class DefaultDisplayExtender extends DisplayExtenderPluginBase {
} }
...@@ -18,9 +18,8 @@ ...@@ -18,9 +18,8 @@
* *
* Display extender plugins extend * Display extender plugins extend
* \Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase. * \Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase.
* They must be annotated with * They must have \Drupal\views\Attribute\ViewsDisplayExtender attributes, and
* \Drupal\views\Annotation\ViewsDisplayExtender annotation, and they * they must be in namespace directory Plugin\views\display_extender.
* must be in namespace directory Plugin\views\display_extender.
* *
* @ingroup views_plugins * @ingroup views_plugins
* *
......
...@@ -4,16 +4,17 @@ ...@@ -4,16 +4,17 @@
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsDisplayExtender;
use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase; use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase;
/** /**
* Defines a display extender test plugin. * Defines a display extender test plugin.
*
* @ViewsDisplayExtender(
* id = "display_extender_test",
* title = @Translation("Display extender test")
* )
*/ */
#[ViewsDisplayExtender(
id: 'display_extender_test',
title: new TranslatableMarkup('Display extender test'),
)]
class DisplayExtenderTest extends DisplayExtenderPluginBase { class DisplayExtenderTest extends DisplayExtenderPluginBase {
/** /**
......
...@@ -2,14 +2,16 @@ ...@@ -2,14 +2,16 @@
namespace Drupal\views_test_data\Plugin\views\display_extender; namespace Drupal\views_test_data\Plugin\views\display_extender;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsDisplayExtender;
/** /**
* Defines another display extender test plugin. * Defines another display extender test plugin.
*
* @ViewsDisplayExtender(
* id = "display_extender_test_2",
* title = @Translation("Display extender test number two")
* )
*/ */
#[ViewsDisplayExtender(
id: 'display_extender_test_2',
title: new TranslatableMarkup('Display extender test number two'),
)]
class DisplayExtenderTest2 extends DisplayExtenderTest { class DisplayExtenderTest2 extends DisplayExtenderTest {
} }
...@@ -2,14 +2,16 @@ ...@@ -2,14 +2,16 @@
namespace Drupal\views_test_data\Plugin\views\display_extender; namespace Drupal\views_test_data\Plugin\views\display_extender;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsDisplayExtender;
/** /**
* Defines the third display extender test plugin. * Defines the third display extender test plugin.
*
* @ViewsDisplayExtender(
* id = "display_extender_test_3",
* title = @Translation("Display extender test number three")
* )
*/ */
#[ViewsDisplayExtender(
id: 'display_extender_test_3',
title: new TranslatableMarkup('Display extender test number three'),
)]
class DisplayExtenderTest3 extends DisplayExtenderTest { class DisplayExtenderTest3 extends DisplayExtenderTest {
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment