Skip to content
Snippets Groups Projects
Verified Commit 99fc4306 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3420984 by godotislate, andypost, smustgrave, larowlan, alexpott:...

Issue #3420984 by godotislate, andypost, smustgrave, larowlan, alexpott: Convert Layout DisplayVariant, PageDisplayVariant discovery to attributes
parent c8ff8fd5
No related branches found
No related tags found
27 merge requests!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8540Issue #3457061: Bootstrap Modal dialog Not closing after 10.3.0 Update,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8373Issue #3427374 by danflanagan8, Vighneshh: taxonomy_tid ViewsArgumentDefault...,!7526Expose roles in response,!7352Draft: Resolve #3203489 "Set filename as",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2794Issue #3100732: Allow specifying `meta` data on JSON:API objects,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #124911 canceled
Showing
with 98 additions and 23 deletions
......@@ -2169,7 +2169,7 @@ function hook_countries_alter(&$countries) {
* The array of display variant definitions, keyed by plugin ID.
*
* @see \Drupal\Core\Display\VariantManager
* @see \Drupal\Core\Display\Annotation\DisplayVariant
* @see \Drupal\Core\Display\Attribute\DisplayVariant
*/
function hook_display_variant_plugin_alter(array &$definitions) {
$definitions['full_page']['admin_label'] = t('Block layout');
......
<?php
namespace Drupal\Core\Display\Attribute;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines a display variant attribute object.
*
* Display variants are used to dictate the output of a given Display, which
* can be used to control the output of many parts of Drupal.
*
* Variants are usually chosen by some selection criteria, and are instantiated
* directly. Each variant must define its own approach to rendering, and can
* either load its own data or be injected with data from another Display
* object.
*
* Plugin namespace: Plugin\DisplayVariant
*
* For working examples, see
* - \Drupal\Core\Render\Plugin\DisplayVariant\SimplePageVariant
* - \Drupal\block\Plugin\DisplayVariant\BlockPageVariant
*
* @see \Drupal\Core\Display\VariantInterface
* @see \Drupal\Core\Display\VariantBase
* @see \Drupal\Core\Display\VariantManager
* @see \Drupal\Core\Display\PageVariantInterface
* @see plugin_api
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class DisplayVariant extends Plugin {
/**
* Constructs a DisplayVariant plugin attribute object.
*
* @param string $id
* The plugin ID.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup $admin_label
* The administrative label.
* @param class-string|null $deriver
* (optional) The deriver class.
*/
public function __construct(
public readonly string $id,
public readonly TranslatableMarkup $admin_label,
public readonly ?string $deriver = NULL
) {}
}
<?php
namespace Drupal\Core\Display\Attribute;
/**
* Defines a page display variant attribute object.
*
* Page display variants are a specific type of display variant, intended to
* render entire pages. They must render the crucial parts of a page, which are:
* - the title
* - the main content
* - any messages (#type => status_messages)
*
* @see \Drupal\Core\Display\VariantInterface
* @see \Drupal\Core\Display\PageVariantInterface
* @see \Drupal\Core\Display\VariantBase
* @see \Drupal\Core\Display\VariantManager
* @see plugin_api
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class PageDisplayVariant extends DisplayVariant {}
......@@ -14,7 +14,7 @@
* display variant is used by the Block module to control regions and output
* blocks placed in those regions.
*
* @see \Drupal\Core\Display\Annotation\DisplayVariant
* @see \Drupal\Core\Display\Attribute\DisplayVariant
* @see \Drupal\Core\Display\VariantBase
* @see \Drupal\Core\Display\VariantManager
* @see plugin_api
......
......@@ -11,7 +11,7 @@
/**
* Provides a base class for DisplayVariant plugins.
*
* @see \Drupal\Core\Display\Annotation\DisplayVariant
* @see \Drupal\Core\Display\Attribute\DisplayVariant
* @see \Drupal\Core\Display\VariantInterface
* @see \Drupal\Core\Display\VariantManager
* @see plugin_api
......
......@@ -12,7 +12,7 @@
/**
* Provides an interface for DisplayVariant plugins.
*
* @see \Drupal\Core\Display\Annotation\DisplayVariant
* @see \Drupal\Core\Display\Attribute\DisplayVariant
* @see \Drupal\Core\Display\VariantBase
* @see \Drupal\Core\Display\VariantManager
* @see plugin_api
......
......@@ -3,13 +3,14 @@
namespace Drupal\Core\Display;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Display\Attribute\DisplayVariant;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
/**
* Manages discovery of display variant plugins.
*
* @see \Drupal\Core\Display\Annotation\DisplayVariant
* @see \Drupal\Core\Display\Attribute\DisplayVariant
* @see \Drupal\Core\Display\VariantInterface
* @see \Drupal\Core\Display\VariantBase
* @see plugin_api
......@@ -28,7 +29,7 @@ class VariantManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/DisplayVariant', $namespaces, $module_handler, 'Drupal\Core\Display\VariantInterface', 'Drupal\Core\Display\Annotation\DisplayVariant');
parent::__construct('Plugin/DisplayVariant', $namespaces, $module_handler, 'Drupal\Core\Display\VariantInterface', DisplayVariant::class, 'Drupal\Core\Display\Annotation\DisplayVariant');
$this->setCacheBackend($cache_backend, 'variant_plugins');
$this->alterInfo('display_variant_plugin');
......
......@@ -2,17 +2,18 @@
namespace Drupal\Core\Render\Plugin\DisplayVariant;
use Drupal\Core\Display\Attribute\PageDisplayVariant;
use Drupal\Core\Display\PageVariantInterface;
use Drupal\Core\Display\VariantBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Provides a page display variant that simply renders the main content.
*
* @PageDisplayVariant(
* id = "simple_page",
* admin_label = @Translation("Simple page")
* )
*/
#[PageDisplayVariant(
id: 'simple_page',
admin_label: new TranslatableMarkup('Simple page')
)]
class SimplePageVariant extends VariantBase implements PageVariantInterface {
/**
......
......@@ -455,8 +455,8 @@
* ways: no decoration at all (just a page showing the main content) or blocks
* (a page with regions, with blocks positioned in regions around the main
* content). Modules can provide additional options, by implementing a page
* variant, which is a plugin annotated with
* \Drupal\Core\Display\Annotation\PageDisplayVariant.
* variant, which is a plugin with the
* \Drupal\Core\Display\Attribute\PageDisplayVariant attribute.
*
* Routes whose controllers return a \Symfony\Component\HttpFoundation\Response
* object are fully handled by the Symfony render pipeline.
......
......@@ -7,10 +7,12 @@
use Drupal\Core\Block\TitleBlockPluginInterface;
use Drupal\Core\Block\MessagesBlockPluginInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Display\Attribute\PageDisplayVariant;
use Drupal\Core\Display\PageVariantInterface;
use Drupal\Core\Entity\EntityViewBuilderInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Display\VariantBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -23,12 +25,11 @@
*
* @see \Drupal\Core\Block\MainContentBlockPluginInterface
* @see \Drupal\Core\Block\MessagesBlockPluginInterface
*
* @PageDisplayVariant(
* id = "block_page",
* admin_label = @Translation("Page with blocks")
* )
*/
#[PageDisplayVariant(
id: 'block_page',
admin_label: new TranslatableMarkup('Page with blocks')
)]
class BlockPageVariant extends VariantBase implements PageVariantInterface, ContainerFactoryPluginInterface {
/**
......
......@@ -3,18 +3,19 @@
namespace Drupal\display_variant_test\Plugin\DisplayVariant;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Display\Attribute\DisplayVariant;
use Drupal\Core\Display\VariantBase;
use Drupal\Core\Display\PageVariantInterface;
use Drupal\Core\Display\ContextAwareVariantInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Provides a display variant that requires configuration.
*
* @DisplayVariant(
* id = "display_variant_test",
* admin_label = @Translation("Test display variant")
* )
*/
#[DisplayVariant(
id: 'display_variant_test',
admin_label: new TranslatableMarkup('Test display variant')
)]
class TestDisplayVariant extends VariantBase implements PageVariantInterface, ContextAwareVariantInterface {
/**
......
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