Skip to content

Commit aeecd8d

Browse files
authored
fix: default create-action URL getting targeted when model doesn't match (#18802)
* Fix create action getting targeted to wrong page * WIP
1 parent a9fc573 commit aeecd8d

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

packages/panels/src/Resources/Pages/ManageRelatedRecords.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,23 +300,28 @@ public function getDefaultActionUrl(Action $action): ?string
300300
return null;
301301
}
302302

303+
$actionModel = $action->getModel();
304+
303305
if (
304306
($action instanceof CreateAction) &&
305-
($relatedResource::hasPage('create'))
307+
($relatedResource::hasPage('create')) &&
308+
(blank($actionModel) || ($actionModel === $relatedResource::getModel()))
306309
) {
307310
return $relatedResource::getUrl('create', shouldGuessMissingParameters: true);
308311
}
309312

310313
if (
311314
($action instanceof EditAction) &&
312-
($relatedResource::hasPage('edit'))
315+
($relatedResource::hasPage('edit')) &&
316+
(blank($actionModel) || ($actionModel === $relatedResource::getModel()))
313317
) {
314318
return $relatedResource::getUrl('edit', ['record' => $action->getRecord()], shouldGuessMissingParameters: true);
315319
}
316320

317321
if (
318322
($action instanceof ViewAction) &&
319-
($relatedResource::hasPage('view'))
323+
($relatedResource::hasPage('view')) &&
324+
(blank($actionModel) || ($actionModel === $relatedResource::getModel()))
320325
) {
321326
return $relatedResource::getUrl('view', ['record' => $action->getRecord()], shouldGuessMissingParameters: true);
322327
}

packages/panels/src/Resources/Pages/Page.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,25 +349,30 @@ public function getDefaultActionRelationship(Action $action): ?Relation
349349

350350
public function getDefaultActionUrl(Action $action): ?string
351351
{
352+
$actionModel = $action->getModel();
353+
352354
if (
353355
($action instanceof CreateAction) &&
354-
(static::getResource()::hasPage('create'))
356+
(static::getResource()::hasPage('create')) &&
357+
(blank($actionModel) || ($actionModel === static::getResource()::getModel()))
355358
) {
356359
return $this->getResourceUrl('create');
357360
}
358361

359362
if (
360363
($action instanceof EditAction) &&
361364
(static::getResource()::hasPage('edit')) &&
362-
(! $this instanceof EditRecord)
365+
(! $this instanceof EditRecord) &&
366+
(blank($actionModel) || ($actionModel === static::getResource()::getModel()))
363367
) {
364368
return $this->getResourceUrl('edit', ['record' => $action->getRecord()]);
365369
}
366370

367371
if (
368372
($action instanceof ViewAction) &&
369373
(static::getResource()::hasPage('view')) &&
370-
(! $this instanceof ViewRecord)
374+
(! $this instanceof ViewRecord) &&
375+
(blank($actionModel) || ($actionModel === static::getResource()::getModel()))
371376
) {
372377
return $this->getResourceUrl('view', ['record' => $action->getRecord()]);
373378
}

packages/panels/src/Resources/RelationManagers/RelationManager.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,23 +377,28 @@ public function getDefaultActionUrl(Action $action): ?string
377377
return null;
378378
}
379379

380+
$actionModel = $action->getModel();
381+
380382
if (
381383
($action instanceof CreateAction) &&
382-
($relatedResource::hasPage('create'))
384+
($relatedResource::hasPage('create')) &&
385+
(blank($actionModel) || ($actionModel === $relatedResource::getModel()))
383386
) {
384387
return $relatedResource::getUrl('create', shouldGuessMissingParameters: true);
385388
}
386389

387390
if (
388391
($action instanceof EditAction) &&
389-
($relatedResource::hasPage('edit'))
392+
($relatedResource::hasPage('edit')) &&
393+
(blank($actionModel) || ($actionModel === $relatedResource::getModel()))
390394
) {
391395
return $relatedResource::getUrl('edit', ['record' => $action->getRecord()], shouldGuessMissingParameters: true);
392396
}
393397

394398
if (
395399
($action instanceof ViewAction) &&
396-
($relatedResource::hasPage('view'))
400+
($relatedResource::hasPage('view')) &&
401+
(blank($actionModel) || ($actionModel === $relatedResource::getModel()))
397402
) {
398403
return $relatedResource::getUrl('view', ['record' => $action->getRecord()], shouldGuessMissingParameters: true);
399404
}

0 commit comments

Comments
 (0)