Skip to content

Commit

Permalink
fixed edit URL for getFormFieldsForBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
zeezo887 committed Mar 25, 2024
1 parent a2c5df6 commit 0ad0510
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/Repositories/Behaviors/HandleBrowsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,13 @@ public function getFormFieldsForBrowser(
) {
$fields = $this->getRelatedElementsAsCollection($object, $relation);

$isMorphTo = method_exists($object, $relation) && $object->$relation() instanceof MorphTo;

if ($fields->isNotEmpty()) {
return $fields->map(
function ($relatedElement) use ($titleKey, $routePrefix, $relation, $moduleName, $isMorphTo) {
if ($isMorphTo && !$moduleName) {
// @todo: Maybe there is an existing helper for this?
$moduleName = Str::plural(Arr::last(explode('\\', get_class($relatedElement))));
}

function ($relatedElement) use ($titleKey, $routePrefix, $moduleName) {
return [
'id' => $relatedElement->id,
'name' => $relatedElement->titleInBrowser ?? $relatedElement->$titleKey,
'edit' => $this->getAdminEditUrl($relatedElement),
'edit' => $this->getAdminEditUrl($relatedElement, $routePrefix, $moduleName),
'endpointType' => $relatedElement->getMorphClass(),
] + (classHasTrait($relatedElement, HasMedias::class) ? [
'thumbnail' => $relatedElement->defaultCmsImage(['w' => 100, 'h' => 100, 'fit' => 'crop']),
Expand Down Expand Up @@ -238,17 +231,17 @@ public function getFormFieldsForRelatedBrowser($object, $relation, $titleKey = '
* @param $object
* @return mixed|string
*/
public function getAdminEditUrl($object): mixed
public function getAdminEditUrl($object, $routePrefix = null, $moduleName = null): mixed
{
if (!empty($object->adminEditUrl)) {
return $object->adminEditUrl;

Check warning on line 237 in src/Repositories/Behaviors/HandleBrowsers.php

View check run for this annotation

Codecov / codecov/patch

src/Repositories/Behaviors/HandleBrowsers.php#L237

Added line #L237 was not covered by tests
}

$module = getModuleNameByModel($object);
$moduleName = $moduleName ?? getModuleNameByModel($object);

return moduleRoute(
$module,
config('twill.block_editor.browser_route_prefixes.' . $module),
$moduleName,
$routePrefix ?? config('twill.block_editor.browser_route_prefixes.' . $moduleName),
'edit',
$object->id
);
Expand Down

0 comments on commit 0ad0510

Please sign in to comment.