Open zeezo887 opened 5 months ago
Also just encountered this issue, the PR doesn't fix it entirely though
getModuleNameByModel() is not working properly if the model has a different name than the module (which it could have)
The fix is
function getModuleNameByModel($model)
{
try {
return TwillCapsules::getCapsuleForModel($model)->getModule();
} catch (NoCapsuleFoundException) {
return Str::plural(lcfirst(class_basename($model)));
}
}
public function getCapsuleForModel(string|TwillModelContract $model): Capsule
{
if ($model instanceof TwillModelContract) {
$model = get_class($model);
}
$model = class_basename($model);
$capsule = $this->getRegisteredCapsules()->first(function (Capsule $capsule) use ($model) {
return $capsule->getSingular() === $model;
});
if (!$capsule) {
throw new NoCapsuleFoundException($model);
}
return $capsule;
}
Even with all this changes, the issue is still not fixed, newly added relations do get the correct link, but not the ones that were loaded when loading the page
There is another
'edit' => $relatedElement->adminEditUrl ?? moduleRoute(
$moduleName ?? $relation,
$routePrefix ?? '',
'edit',
$relatedElement->id
),
In handle browsers that needs to be replaced with 'edit' => $this->getAdminUrl($relatedElement)
After that it works correctly
@Tofandel Thanks for this! I didn't consider that a module name could be different from the model. Your suggested changes worked fine.
Thanks, there is still this https://github.com/area17/twill/pull/2533/files#diff-3b134878262a01ad247d37cebcf578142d170ece67db85d1c31b8d0831c29c71R204-R208 To change according to my last comment
Description
This resolves the issue where the edit URL of a block browser item fails to function properly when the browser name doesn't match the item module name.
Related Issues
Relates to #2278