mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-04 10:16:51 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			74 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Filament\Server\Pages;
 | 
						|
 | 
						|
use App\Models\Server;
 | 
						|
use App\Traits\Filament\BlockAccessInConflict;
 | 
						|
use App\Traits\Filament\CanCustomizeHeaderActions;
 | 
						|
use App\Traits\Filament\CanCustomizeHeaderWidgets;
 | 
						|
use Filament\Facades\Filament;
 | 
						|
use Filament\Forms\Concerns\InteractsWithForms;
 | 
						|
use Filament\Forms\Form;
 | 
						|
use Filament\Pages\Concerns\InteractsWithFormActions;
 | 
						|
use Filament\Pages\Page;
 | 
						|
 | 
						|
/**
 | 
						|
 * @property Form $form
 | 
						|
 */
 | 
						|
abstract class ServerFormPage extends Page
 | 
						|
{
 | 
						|
    use BlockAccessInConflict;
 | 
						|
    use CanCustomizeHeaderActions;
 | 
						|
    use CanCustomizeHeaderWidgets;
 | 
						|
    use InteractsWithFormActions;
 | 
						|
    use InteractsWithForms;
 | 
						|
 | 
						|
    protected static string $view = 'filament.server.pages.server-form-page';
 | 
						|
 | 
						|
    /** @var ?array<mixed> */
 | 
						|
    public ?array $data = [];
 | 
						|
 | 
						|
    public function mount(): void
 | 
						|
    {
 | 
						|
        $this->authorizeAccess();
 | 
						|
 | 
						|
        $this->fillForm();
 | 
						|
    }
 | 
						|
 | 
						|
    protected function authorizeAccess(): void {}
 | 
						|
 | 
						|
    protected function fillForm(): void
 | 
						|
    {
 | 
						|
        $data = $this->getRecord()->attributesToArray();
 | 
						|
        $this->form->fill($data);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @return array<int | string, string | Form>
 | 
						|
     */
 | 
						|
    protected function getForms(): array
 | 
						|
    {
 | 
						|
        return [
 | 
						|
            'form' => $this->form($this->makeForm()
 | 
						|
                ->model($this->getRecord())
 | 
						|
                ->statePath($this->getFormStatePath())
 | 
						|
                ->columns($this->hasInlineLabels() ? 1 : 2)
 | 
						|
                ->inlineLabel($this->hasInlineLabels()),
 | 
						|
            ),
 | 
						|
        ];
 | 
						|
    }
 | 
						|
 | 
						|
    public function getFormStatePath(): ?string
 | 
						|
    {
 | 
						|
        return 'data';
 | 
						|
    }
 | 
						|
 | 
						|
    public function getRecord(): Server
 | 
						|
    {
 | 
						|
        /** @var Server $server */
 | 
						|
        $server = Filament::getTenant();
 | 
						|
 | 
						|
        return $server;
 | 
						|
    }
 | 
						|
}
 |