diff --git a/src/View/Components/Fields/Browser.php b/src/View/Components/Fields/Browser.php index 1eda053bf..a733fc828 100644 --- a/src/View/Components/Fields/Browser.php +++ b/src/View/Components/Fields/Browser.php @@ -50,8 +50,8 @@ public function __construct( default: $default ); - if (!$this->endpoints) { - $endpointsFromModules = isset($this->modules) ? collect($this->modules)->map(function ($module) { + if (!$this->endpoints && isset($this->modules)) { + $this->endpoints = collect($this->modules)->map(function ($module) { return [ 'label' => $module['label'] ?? ucfirst($module['name']), 'value' => moduleRoute( @@ -62,16 +62,14 @@ public function __construct( false ), ]; - })->toArray() : null; + })->toArray(); } - $this->endpoints = $this->endpoints === [] ? $endpointsFromModules ?? [] : []; - if (empty($this->endpoints)) { - $routeEndpoint = $this->moduleName; - if ($this->routePrefix) { - $routeEndpoint = Str::replaceFirst($this->routePrefix . '.', '', $this->moduleName); - } + $routeEndpoint = $this->routePrefix + ? Str::replaceFirst($this->routePrefix . '.', '', $this->moduleName) + : $this->moduleName; + $this->endpoint = $this->endpoint ?? (empty($endpoints) ? moduleRoute( // Remove the route prefix from the moduleName. $routeEndpoint,