36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\Rbac\Actions;
|
|
|
|
use App\Models\Tenant;
|
|
use App\Models\Workspace;
|
|
use Filament\Facades\Filament;
|
|
|
|
trait ResolvesUiActionContext
|
|
{
|
|
protected static function tenantUiActionContext(
|
|
?Tenant $tenant = null,
|
|
UiActionContextSource $source = UiActionContextSource::PageResolver,
|
|
): UiActionContext {
|
|
if (! $tenant instanceof Tenant && method_exists(static::class, 'resolveTenantContextForCurrentPanel')) {
|
|
$tenant = static::resolveTenantContextForCurrentPanel();
|
|
}
|
|
|
|
if (! $tenant instanceof Tenant) {
|
|
$filamentTenant = Filament::getTenant();
|
|
$tenant = $filamentTenant instanceof Tenant ? $filamentTenant : null;
|
|
}
|
|
|
|
return UiActionContext::forEnvironment($tenant, $source);
|
|
}
|
|
|
|
protected static function workspaceUiActionContext(
|
|
?Workspace $workspace = null,
|
|
UiActionContextSource $source = UiActionContextSource::WorkspaceContext,
|
|
): UiActionContext {
|
|
return UiActionContext::forWorkspace($workspace, $source);
|
|
}
|
|
}
|