make it easier to transfer an item with the PageAction

This commit is contained in:
Kevin Papst
2026-01-25 15:46:01 +01:00
parent 2ffdaa088f
commit 32c8ec2aaf
2 changed files with 22 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ class PageActionsEvent extends ThemeEvent
{
private int $divider = 0;
private ?string $locale = null;
private ?object $item = null;
/**
* @param array<mixed> $payload
@@ -32,10 +33,17 @@ class PageActionsEvent extends ThemeEvent
if (!\array_key_exists('actions', $payload)) {
$payload['actions'] = [];
}
// only for BC reasons, do not access it directly!
if (!\array_key_exists('view', $payload)) {
$payload['view'] = $view;
}
if (\array_key_exists('item', $payload)) {
$this->item = $payload['item'];
unset($payload['item']);
}
parent::__construct($user, $payload);
}
@@ -228,4 +236,12 @@ class PageActionsEvent extends ThemeEvent
{
$this->locale = $locale;
}
/**
* Returns null for "listing" pages.
*/
public function getItem(): object|null
{
return $this->item;
}
}

View File

@@ -33,10 +33,15 @@ class PageActionsEventTest extends TestCase
self::assertEquals([], $sut->getActions());
self::assertEquals(['actions' => [], 'view' => 'bar'], $sut->getPayload());
self::assertNull($sut->getLocale());
self::assertNull($sut->getItem());
$sut = new PageActionsEvent($user, ['hello' => 'world'], 'foo', 'bar');
$item = new User();
$sut = new PageActionsEvent($user, ['hello' => 'world', 'item' => $item], 'foo', 'bar');
self::assertSame($user, $sut->getUser());
self::assertEquals([], $sut->getActions());
self::assertNotNull($sut->getItem());
self::assertInstanceOf(User::class, $sut->getItem());
self::assertEquals(['hello' => 'world', 'actions' => [], 'view' => 'bar'], $sut->getPayload());
}