Skip to content
Snippets Groups Projects
Verified Commit 0b80bc53 authored by Dave Long's avatar Dave Long
Browse files

Issue #3410222 by alexpott: Autowiring does not support nullable types

parent b604d68a
No related branches found
No related tags found
12 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...,!6560Update ClaroPreRender.php, confirming classes provided are in array format,!6528Issue #3414261 by catch: Add authenticated user umami performance tests,!6501Issue #3263668 by omkar-pd, Wim Leers, hooroomoo: Re-enable inline form errors...
Checking pipeline status
......@@ -28,7 +28,7 @@ public static function create(ContainerInterface $container) {
if (method_exists(static::class, '__construct')) {
$constructor = new \ReflectionMethod(static::class, '__construct');
foreach ($constructor->getParameters() as $parameter) {
$service = (string) $parameter->getType();
$service = ltrim((string) $parameter->getType(), '?');
foreach ($parameter->getAttributes(Autowire::class) as $attribute) {
$service = (string) $attribute->newInstance()->value;
}
......
......@@ -6,6 +6,7 @@
use Drupal\Core\Cache\CacheableResponse;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Render\Markup;
......@@ -70,6 +71,12 @@ class SystemTestController extends ControllerBase implements TrustedCallbackInte
* The renderer.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
* @param \Drupal\Core\PageCache\ResponsePolicy\KillSwitch|null $killSwitch
* The page cache kill switch. This is here to test nullable types with
* \Drupal\Core\DependencyInjection\AutowireTrait::create().
* @param \Drupal\Core\PageCache\ResponsePolicy\KillSwitch|null $killSwitch2
* The page cache kill switch. This is here to test nullable types with
* \Drupal\Core\DependencyInjection\AutowireTrait::create().
*/
public function __construct(
#[Autowire(service: 'lock')]
......@@ -79,6 +86,8 @@ public function __construct(
AccountInterface $current_user,
RendererInterface $renderer,
MessengerInterface $messenger,
public ?KillSwitch $killSwitch = NULL,
public KillSwitch|null $killSwitch2 = NULL,
) {
$this->lock = $lock;
$this->persistentLock = $persistent_lock;
......
......@@ -26,6 +26,7 @@ class ControllerBaseTest extends KernelTestBase {
* @covers ::create
*/
public function testCreate() {
/** @var \Drupal\system_test\Controller\SystemTestController $controller */
$controller = $this->container->get('class_resolver')->getInstanceFromDefinition(SystemTestController::class);
$property = new \ReflectionProperty(SystemTestController::class, 'lock');
......@@ -36,6 +37,10 @@ public function testCreate() {
$property = new \ReflectionProperty(SystemTestController::class, 'currentUser');
$this->assertSame($this->container->get('current_user'), $property->getValue($controller));
// Test nullables types.
$this->assertSame($this->container->get('page_cache_kill_switch'), $controller->killSwitch);
$this->assertSame($this->container->get('page_cache_kill_switch'), $controller->killSwitch2);
}
/**
......
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