Implements explicit UiActionContext contract as requested. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #434
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\ManagedEnvironment;
|
|
use App\Models\Workspace;
|
|
use Filament\Facades\Filament;
|
|
|
|
trait ResolvesUiActionContext
|
|
{
|
|
protected static function tenantUiActionContext(
|
|
?ManagedEnvironment $tenant = null,
|
|
UiActionContextSource $source = UiActionContextSource::PageResolver,
|
|
): UiActionContext {
|
|
if (! $tenant instanceof ManagedEnvironment && method_exists(static::class, 'resolveTenantContextForCurrentPanel')) {
|
|
$tenant = static::resolveTenantContextForCurrentPanel();
|
|
}
|
|
|
|
if (! $tenant instanceof ManagedEnvironment) {
|
|
$filamentTenant = Filament::getTenant();
|
|
$tenant = $filamentTenant instanceof ManagedEnvironment ? $filamentTenant : null;
|
|
}
|
|
|
|
return UiActionContext::forEnvironment($tenant, $source);
|
|
}
|
|
|
|
protected static function workspaceUiActionContext(
|
|
?Workspace $workspace = null,
|
|
UiActionContextSource $source = UiActionContextSource::WorkspaceContext,
|
|
): UiActionContext {
|
|
return UiActionContext::forWorkspace($workspace, $source);
|
|
}
|
|
}
|