Skip to content

Commit

Permalink
Merge pull request #30 from puzzledmonkey/patch-1
Browse files Browse the repository at this point in the history
Add support for Lens names
  • Loading branch information
ianrobertsFF authored Mar 4, 2023
2 parents 420158b + 6e96544 commit a4f260d
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Formfeed\Breadcrumbs;

use Laravel\Nova\Http\Requests\LensRequest;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Menu\Breadcrumbs as NovaBreadcrumbs;
use Laravel\Nova\Dashboard;
Expand All @@ -27,6 +28,7 @@ class Breadcrumbs extends NovaBreadcrumbs {
protected static $formBreadcrumbCallback;
protected static $resourceBreadcrumbCallback;
protected static $dashboardBreadcrumbCallback;
protected static $lensBreadcrumbCallback;
protected static $rootBreadcrumbCallback;
protected static $groupBreadcrumbCallback;

Expand All @@ -50,6 +52,10 @@ public static function dashboardCallback(callable $callback) {
static::$dashboardBreadcrumbCallback = $callback;
}

public static function lensCallback(callable $callback) {
static::$lensBreadcrumbCallback = $callback;
}

public static function rootCallback(callable $callback) {
static::$rootBreadcrumbCallback = $callback;
}
Expand Down Expand Up @@ -87,6 +93,10 @@ protected function breadcrumbArray(NovaRequest $request) {
}

$this->getRelationshipTree($this->resource);

if ($this->pageType($request) === "lens") {
array_push($this->items, ...$this->lensBreadcrumb($request));
}
}

protected function getRelationshipTree($resource) {
Expand Down Expand Up @@ -174,7 +184,7 @@ protected function detailBreadcrumb(NovaRequest $request, $resource) {
protected function formBreadcrumb($request, $resource) {
$type = $this->pageType($request);

if (!is_null($type) && in_array($type, ["index", "detail", "dashboard"])) {
if (!is_null($type) && in_array($type, ["index", "detail", "dashboard", "lens"])) {
return [];
}

Expand Down Expand Up @@ -217,6 +227,25 @@ protected function dashboardBreadcrumb(NovaRequest $request) {
return Arr::wrap(Breadcrumb::make($dashboard?->label() ?? __("Dashboard")));
}

protected function lensBreadcrumb(NovaRequest $request) {

$lens = LensRequest::createFrom($request)->lens();

if (is_null($lens)) {
return;
}

if (method_exists($lens, "lensBreadcrumb")) {
return Arr::wrap($lens->lensBreadcrumb($request, $this, Breadcrumb::make($lens?->name() ?? __("Lens"))));
}

if (!is_null(static::$lensBreadcrumbCallback)) {
return Arr::wrap(call_user_func_array(static::$lensBreadcrumbCallback, [$request, $this, Breadcrumb::make($lens?->name() ?? __("Lens"))]));
}

return Arr::wrap(Breadcrumb::make($lens?->name() ?? __("Lens")));
}

protected function resourceBreadcrumbs(NovaRequest $request, $resource, $breadcrumbArray) {

if (method_exists($resource, "breadcrumbs")) {
Expand Down Expand Up @@ -269,6 +298,8 @@ protected function pageType(NovaRequest $request) {
return "attach";
case Pages\DashboardController::class:
return "dashboard";
case Pages\LensController::class:
return "lens";
default:
return null;
}
Expand Down

0 comments on commit a4f260d

Please sign in to comment.