Skip to content
Snippets Groups Projects
Verified Commit f2670656 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

(cherry picked from commit 99fc4306)
parent cde3ff56
No related branches found
No related tags found
25 merge requests!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!7401#3271894 Fix documented StreamWrapperInterface return types for realpath() and dirname(),!7384Add constraints to system.advisories,!6622Issue #2559833 by piggito, mohit_aghera, larowlan, guptahemant, vakulrai,...,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #124898 passed with warnings
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