Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Jul 31, 2024
1 parent 06a66eb commit 9e0b750
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/04-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ You can also pass an array of arguments to the default action using the `$defaul
public $defaultActionArguments = ['step' => 2];
```

Alternatively, you can open an action modal when a page loads by specifying the `defaultAction` as a query string parameter to the page:
Alternatively, you can open an action modal when a page loads by specifying the `action` as a query string parameter to the page:

```
/admin/products/edit/932510?defaultAction=onboarding
/admin/products/edit/932510?action=onboarding
```

### Refreshing form data
Expand Down
1 change: 1 addition & 0 deletions src/Facades/Filament.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
* @method static string | null getRequestPasswordResetUrl(array $parameters = [])
* @method static string getResetPasswordUrl(string $token, CanResetPassword | Model | Authenticatable $user, array $parameters = [])
* @method static array getResources()
* @method static array getResourceUrl(string | Model $model, string $name = 'index', array $parameters = [], bool $isAbsolute = false, ?Model $tenant = null)
* @method static string getSidebarWidth()
* @method static Model | null getTenant()
* @method static string | null getTenantAvatarUrl(Model $tenant)
Expand Down
9 changes: 9 additions & 0 deletions src/FilamentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event;
use Throwable;

class FilamentManager
{
Expand Down Expand Up @@ -342,6 +343,14 @@ public function getResources(): array
return $this->getCurrentPanel()->getResources();
}

/**
* @param array<mixed> $parameters
*/
public function getResourceUrl(string | Model $model, string $name = 'index', array $parameters = [], bool $isAbsolute = true, ?Model $tenant = null): string
{
return $this->getCurrentPanel()->getResourceUrl($model, $name, $parameters, $isAbsolute, $tenant);
}

public function getSidebarWidth(): string
{
return $this->getCurrentPanel()->getSidebarWidth();
Expand Down
6 changes: 3 additions & 3 deletions src/FilamentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public function configurePackage(Package $package): void
public function packageRegistered(): void
{
$this->app->scoped('filament', function (): FilamentManager {
return new FilamentManager();
return new FilamentManager;
});

$this->app->singleton(PanelRegistry::class, function (): PanelRegistry {
return new PanelRegistry();
return new PanelRegistry;
});

$this->app->scoped(NavigationManager::class, function (): NavigationManager {
return new NavigationManager();
return new NavigationManager;
});

$this->app->bind(EmailVerificationResponseContract::class, EmailVerificationResponse::class);
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/BasePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function onValidationError(ValidationException $exception): void

protected function halt(): void
{
throw new Halt();
throw new Halt;
}

protected function callHook(string $hook): void
Expand Down
1 change: 1 addition & 0 deletions src/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class Panel extends Component
{
use Panel\Concerns\CanGenerateResourceUrls;
use Panel\Concerns\HasAssets;
use Panel\Concerns\HasAuth;
use Panel\Concerns\HasAvatars;
Expand Down
29 changes: 29 additions & 0 deletions src/Panel/Concerns/CanGenerateResourceUrls.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Filament\Panel\Concerns;

use Exception;
use Illuminate\Database\Eloquent\Model;
use Throwable;

trait CanGenerateResourceUrls
{
/**
* @param array<mixed> $parameters
*/
public function getResourceUrl(string | Model $model, string $name = 'index', array $parameters = [], bool $isAbsolute = true, ?Model $tenant = null): string
{
$modelClass = is_string($model) ? $model : $model::class;

$resource = $this->getModelResource($modelClass) ?? throw new Exception("No Filament resource found for model [{$modelClass}].");

if (
($model instanceof Model) &&
in_array($name, ['edit', 'view'])
) {
$parameters['record'] ??= $model;
}

return $resource::getUrl($name, $parameters, $isAbsolute, $this->getId(), $tenant);
}
}
2 changes: 1 addition & 1 deletion src/Panel/Concerns/HasRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function getUrl(?Model $tenant = null): ?string
Filament::setTenant($tenant, isQuiet: true);
}

$this->navigationManager = new NavigationManager();
$this->navigationManager = new NavigationManager;

$navigation = $this->navigationManager->get();

Expand Down
2 changes: 1 addition & 1 deletion src/Panel/Concerns/HasTenancy.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function getTenant(string $key): Model
->resolveRouteBinding($key, $this->getTenantSlugAttribute());

if ($record === null) {
throw (new ModelNotFoundException())->setModel($tenantModel, [$key]);
throw (new ModelNotFoundException)->setModel($tenantModel, [$key]);
}

return $record;
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Pages/Concerns/InteractsWithRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function resolveRecord(int | string $key): Model
$record = static::getResource()::resolveRecordRouteBinding($key);

if ($record === null) {
throw (new ModelNotFoundException())->setModel($this->getModel(), [$key]);
throw (new ModelNotFoundException)->setModel($this->getModel(), [$key]);
}

return $record;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function authorize(string $action, Model | string $model, bool $shouldCheckPolic
);

if ($response === false) {
throw new AuthorizationException();
throw new AuthorizationException;
}

if (! $response instanceof Response) {
Expand Down

0 comments on commit 9e0b750

Please sign in to comment.