Skip to content

Commit 9d44f77

Browse files
Remove override url name in ActionColumn::class. (#127)
1 parent 82674ce commit 9d44f77

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed

psalm.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0"?>
22
<psalm
33
errorLevel="1"
4+
findUnusedBaselineEntry="true"
5+
findUnusedCode="false"
46
resolveFromConfigFile="true"
57
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
68
xmlns="https://getpsalm.org/schema/config"
@@ -15,6 +17,7 @@
1517

1618
<issueHandlers>
1719
<!-- Do not initialize properties to null. -->
20+
<MixedAssignment errorLevel="suppress" />
1821
<PropertyNotSetInConstructor errorLevel="suppress" />
1922
<RedundantPropertyInitializationCheck errorLevel="suppress" />
2023
</issueHandlers>

src/BasePagination.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ protected function createUrl(int $page): string
338338

339339
$urlName = $this->currentRoute->getName();
340340

341-
return match ($urlName !== null) {
342-
true => $this->urlGenerator->generate($urlName, $urlArguments, $urlQueryParameters),
343-
false => $urlQueryParameters ? '?' . http_build_query($urlQueryParameters) : '',
341+
return match ($urlName) {
342+
null => $urlQueryParameters ? '?' . http_build_query($urlQueryParameters) : '',
343+
default => $this->urlGenerator->generate($urlName, $urlArguments, $urlQueryParameters),
344344
};
345345
}
346346

src/Column/ActionColumn.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use InvalidArgumentException;
99
use Yiisoft\Html\Tag\A;
1010
use Yiisoft\Html\Tag\Span;
11+
use Yiisoft\Router\CurrentRoute;
1112
use Yiisoft\Router\UrlGeneratorInterface;
1213

1314
use function is_array;
@@ -22,6 +23,7 @@ final class ActionColumn extends AbstractColumn
2223
private string $template = '{view}{update}{delete}';
2324
private array|null $urlArguments = null;
2425
private Closure|null $urlCreator = null;
26+
private CurrentRoute $currentRoute;
2527
private UrlGeneratorInterface|null $urlGenerator = null;
2628
private array $urlParamsConfig = [];
2729
private string $urlName = '';
@@ -123,6 +125,14 @@ public function createDefaultButtons(): self
123125
return $new;
124126
}
125127

128+
public function currentRoute(CurrentRoute $value): self
129+
{
130+
$new = clone $this;
131+
$new->currentRoute = $value;
132+
133+
return $new;
134+
}
135+
126136
public function getLabel(): string
127137
{
128138
$label = parent::getLabel();
@@ -370,7 +380,13 @@ private function createUrl(string $action, array|object $data, mixed $key, int $
370380
$key = $data[$this->primaryKey] ?? $key;
371381
}
372382

373-
$route = $this->urlName !== '' ? $this->urlName . '/' . $action : $action;
383+
$currentRouteName = $this->currentRoute->getName() ?? '';
384+
385+
$route = match ($this->urlName) {
386+
'' => $currentRouteName . '/' . $action,
387+
default => $this->urlName . '/' . $action,
388+
};
389+
374390
$urlQueryParameters = [];
375391
$urlParamsConfig = is_array($key) ? $key : [$this->primaryKey => $key];
376392

src/GridView.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ protected function renderItems(): string
297297
* This function tries to guess the columns to show from the given data if {@see columns} are not explicitly
298298
* specified.
299299
*
300-
* @psalm-return list<ActionColumn|DataColumn>
300+
* @psalm-return list<ActionColumn|DataColumn>|list<array>
301301
*/
302302
private function guessColumns(): array
303303
{
@@ -335,7 +335,7 @@ private function guessColumns(): array
335335
* @throws NotInstantiableException
336336
* @throws CircularReferenceException
337337
*
338-
* @psalm-return array<array-key,AbstractColumn|null>
338+
* @psalm-return array<array-key,AbstractColumn>|array
339339
*/
340340
private function renderColumns(): array
341341
{
@@ -352,8 +352,8 @@ private function renderColumns(): array
352352
if ($column instanceof ActionColumn) {
353353
$column = $column
354354
->createDefaultButtons()
355-
->urlGenerator($this->getUrlGenerator())
356-
->urlName($this->currentRoute->getName() ?? '');
355+
->currentRoute($this->currentRoute)
356+
->urlGenerator($this->getUrlGenerator());
357357
}
358358

359359
if ($column instanceof DataColumn) {
@@ -379,7 +379,7 @@ private function renderColumns(): array
379379
*
380380
* @param array $columns The columns of gridview.
381381
*
382-
* @psalm-param array<array-key,AbstractColumn|null> $columns
382+
* @psalm-param array<array-key,AbstractColumn>|array $columns
383383
*/
384384
private function renderColumnGroup(array $columns): string
385385
{
@@ -401,7 +401,7 @@ private function renderColumnGroup(array $columns): string
401401
*
402402
* @return string The rendering result.
403403
*
404-
* @psalm-param array<array-key,AbstractColumn|null> $columns
404+
* @psalm-param array<array-key,AbstractColumn>|array $columns
405405
*/
406406
private function renderFilters(array $columns): string
407407
{
@@ -433,7 +433,7 @@ private function renderFilters(array $columns): string
433433
*
434434
* @param array $columns The columns of gridview.
435435
*
436-
* @psalm-param array<array-key,AbstractColumn|null> $columns
436+
* @psalm-param array<array-key,AbstractColumn>|array $columns
437437
*/
438438
private function renderTableBody(array $columns): string
439439
{
@@ -483,7 +483,7 @@ private function renderTableBody(array $columns): string
483483
*
484484
* @param array $columns The columns of gridview.
485485
*
486-
* @psalm-param array<array-key,AbstractColumn|null> $columns
486+
* @psalm-param array<array-key,AbstractColumn>|array $columns
487487
*/
488488
private function renderTableFooter(array $columns): string
489489
{
@@ -512,7 +512,7 @@ private function renderTableFooter(array $columns): string
512512
*
513513
* @param array $columns The columns of gridview.
514514
*
515-
* @psalm-param array<array-key,AbstractColumn|null> $columns
515+
* @psalm-param array<array-key,AbstractColumn>|array $columns
516516
*/
517517
private function renderTableHeader(array $columns): string
518518
{
@@ -549,7 +549,7 @@ private function renderTableHeader(array $columns): string
549549
* @param mixed $key The key associated with the data.
550550
* @param int $index The zero-based index of the data in the data provider.
551551
*
552-
* @psalm-param array<array-key,AbstractColumn|null> $columns
552+
* @psalm-param array<array-key,AbstractColumn>|array $columns
553553
*/
554554
private function renderTableRow(array $columns, array|object $data, mixed $key, int $index): string
555555
{

src/LinkSorter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ private function createUrl(string $attribute): string
334334

335335
$urlName = $this->currentRoute->getName();
336336

337-
return match ($urlName !== null) {
338-
true => $this->urlGenerator->generate($urlName, $urlArguments, $urlQueryParameters),
339-
false => $urlQueryParameters ? '?' . http_build_query($urlQueryParameters) : '',
337+
return match ($urlName) {
338+
null => $urlQueryParameters ? '?' . http_build_query($urlQueryParameters) : '',
339+
default => $this->urlGenerator->generate($urlName, $urlArguments, $urlQueryParameters),
340340
};
341341
}
342342

src/ListView.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ protected function renderItems(): string
249249
* @param mixed $key The key value associated with the data.
250250
* @param int $index The zero-based index of the data.
251251
*
252-
* @return string {@see afterItem} call result when {@see afterItem} is not a closure.
252+
* @return string call result when {@see afterItem} is not a closure.
253253
*
254254
* {@see afterItem}
255255
*/
@@ -273,7 +273,7 @@ private function renderAfterItem(array|object $data, mixed $key, int $index): st
273273
* @param mixed $key The key value associated with the data.
274274
* @param int $index The zero-based index of the data.
275275
*
276-
* @return string {@see beforeItem} call result or `null` when {@see beforeItem} is not a closure.
276+
* @return string call result or `null` when {@see beforeItem} is not a closure.
277277
*
278278
* {@see beforeItem}
279279
*/

0 commit comments

Comments
 (0)