-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: edit url for block browser items #2533
base: 3.x
Are you sure you want to change the base?
Conversation
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;
} |
$relatedType = $object->getRelation('pivot')->related_type; | ||
$relation = str_contains($relatedType, '\\') | ||
? getModuleNameByModel($relatedType) | ||
: $relatedType; | ||
|
||
return moduleRoute( | ||
$relation, | ||
config('twill.block_editor.browser_route_prefixes.' . $relation), | ||
'edit', | ||
$object->id | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$relatedType = $object->getRelation('pivot')->related_type; | |
$relation = str_contains($relatedType, '\\') | |
? getModuleNameByModel($relatedType) | |
: $relatedType; | |
return moduleRoute( | |
$relation, | |
config('twill.block_editor.browser_route_prefixes.' . $relation), | |
'edit', | |
$object->id | |
); | |
} | |
$module = getModuleNameByModel($object); | |
return moduleRoute( | |
$module, | |
config('twill.block_editor.browser_route_prefixes.' . $module), | |
'edit', | |
$object->id | |
); | |
} |
There is another
In handle browsers that needs to be replaced with 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For backward compatibility
* @param $object | ||
* @return mixed|string | ||
*/ | ||
public function getAdminEditUrl($object): mixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function getAdminEditUrl($object): mixed | |
public function getAdminEditUrl($object, ?string $routePrefix): mixed |
|
||
return moduleRoute( | ||
$module, | ||
config('twill.block_editor.browser_route_prefixes.' . $module), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config('twill.block_editor.browser_route_prefixes.' . $module), | |
$routePrefix ?? config('twill.block_editor.browser_route_prefixes.' . $module), |
'edit', | ||
$relatedElement->id | ||
), | ||
'edit' => $this->getAdminEditUrl($relatedElement), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'edit' => $this->getAdminEditUrl($relatedElement), | |
'edit' => $this->getAdminEditUrl($relatedElement, $routePrefix), |
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