Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LiveComponent/src/Metadata/LiveComponentMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getAllUrlMappings(object $component): array

foreach ($this->getAllLivePropsMetadata($component) as $livePropMetadata) {
if ($livePropMetadata->urlMapping()) {
$urlMappings[$livePropMetadata->getName()] = $livePropMetadata->urlMapping();
$urlMappings[$livePropMetadata->calculateFieldName($component, $livePropMetadata->getName())] = $livePropMetadata->urlMapping();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class ComponentWithUrlBoundProps
#[LiveProp(url: true)]
public array $arrayProp = [];

#[LiveProp(url: new UrlMapping(as: 'arr_alias'))]
public array $arrayPropAlias = [];

#[LiveProp(writable: true, fieldName: 'getArrayFieldName()', url: true)]
public array $arrayPropFieldName = [];

#[LiveProp]
public ?string $unboundProp = null;

Expand Down Expand Up @@ -113,4 +119,9 @@ public function updateLiveProp(#[LiveArg] string $propName, #[LiveArg] mixed $pr

$this->{$propName} = $propValue;
}

public function getArrayFieldName(): string
{
return 'arr_field_name';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public function testQueryStringMappingAttribute()
'objectPropWithSerializerForHydration' => ['name' => 'objectPropWithSerializerForHydration'],
'propertyWithModifierAndAlias' => ['name' => 'alias_p'],
'pathPropForAnotherController' => ['name' => 'pathPropForAnotherController'],
'arrayPropAlias' => ['name' => 'arr_alias'],
'arr_field_name' => ['name' => 'arr_field_name'],
];

$this->assertEquals($expected, $queryMapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function getTestData(): iterable
'propValue' => 'bar',
],
];

yield 'Changes in prop, with two path params but only one prop' => [
'previousLocation' => '/route_with_two_path_params_but_one_prop/foo/30',
'expectedLocation' => '/route_with_two_path_params_but_one_prop/bar/30',
Expand All @@ -140,6 +141,42 @@ public function getTestData(): iterable
],
];

yield 'Change in query (array)' => [
'previousLocation' => '/route_with_prop/foo',
'expectedLocation' => '/route_with_prop/foo?arrayProp%5B0%5D=hello&arrayProp%5B1%5D=world',
'initialComponentData' => [
'pathProp' => 'foo',
],
'args' => [
'propName' => 'arrayProp',
'propValue' => ['hello', 'world'],
],
];

yield 'Change in query (array & alias)' => [
'previousLocation' => '/route_with_prop/foo',
'expectedLocation' => '/route_with_prop/foo?arr_alias%5B0%5D=hello&arr_alias%5B1%5D=world',
'initialComponentData' => [
'pathProp' => 'foo',
],
'args' => [
'propName' => 'arrayPropAlias',
'propValue' => ['hello', 'world'],
],
];

yield 'Change in query (array & field name)' => [
'previousLocation' => '/route_with_prop/foo',
'expectedLocation' => '/route_with_prop/foo?arr_field_name%5B0%5D=hello&arr_field_name%5B1%5D=world',
'initialComponentData' => [
'pathProp' => 'foo',
],
'args' => [
'propName' => 'arrayPropFieldName',
'propValue' => ['hello', 'world'],
],
];

yield 'Changes in props and query' => [
'previousLocation' => '/route_with_prop/foo',
'expectedLocation' => '/route_with_prop/baz?q=foo+bar',
Expand Down
Loading