| null */ public ?array $data = []; public function getBreadcrumb(): string { return static::$breadcrumb ?? __('filament-panels::resources/pages/view-record.breadcrumb'); } public function getContentTabLabel(): ?string { return __('filament-panels::resources/pages/view-record.content.tab.label'); } public function mount(int | string $record): void { $this->record = $this->resolveRecord($record); $this->authorizeAccess(); if (! $this->hasInfolist()) { $this->fillForm(); } } protected function authorizeAccess(): void { static::authorizeResourceAccess(); abort_unless(static::getResource()::canView($this->getRecord()), 403); } protected function hasInfolist(): bool { return (bool) count($this->getInfolist('infolist')->getComponents()); } protected function fillForm(): void { $data = $this->getRecord()->attributesToArray(); /** @internal Read the DocBlock above the following method. */ $this->fillFormWithDataAndCallHooks($data); } /** * @internal Never override or call this method. If you completely override `fillForm()`, copy the contents of this method into your override. * * @param array $data */ protected function fillFormWithDataAndCallHooks(array $data): void { $this->callHook('beforeFill'); $data = $this->mutateFormDataBeforeFill($data); $this->form->fill($data); $this->callHook('afterFill'); } /** * @param array $attributes */ protected function refreshFormData(array $attributes): void { $this->data = [ ...$this->data, ...$this->getRecord()->only($attributes), ]; } /** * @param array $data * @return array */ protected function mutateFormDataBeforeFill(array $data): array { return $data; } protected function configureAction(Action $action): void { $action ->record($this->getRecord()) ->recordTitle($this->getRecordTitle()); match (true) { $action instanceof DeleteAction => $this->configureDeleteAction($action), $action instanceof EditAction => $this->configureEditAction($action), $action instanceof ForceDeleteAction => $this->configureForceDeleteAction($action), $action instanceof ReplicateAction => $this->configureReplicateAction($action), $action instanceof RestoreAction => $this->configureRestoreAction($action), default => null, }; } protected function configureEditAction(EditAction $action): void { $resource = static::getResource(); $action ->authorize($resource::canEdit($this->getRecord())) ->form(fn (Form $form): Form => static::getResource()::form($form)); if ($resource::hasPage('edit')) { $action->url(fn (): string => static::getResource()::getUrl('edit', ['record' => $this->getRecord()])); } } protected function configureForceDeleteAction(ForceDeleteAction $action): void { $resource = static::getResource(); $action ->authorize($resource::canForceDelete($this->getRecord())) ->successRedirectUrl($resource::getUrl('index')); } protected function configureReplicateAction(ReplicateAction $action): void { $action ->authorize(static::getResource()::canReplicate($this->getRecord())); } protected function configureRestoreAction(RestoreAction $action): void { $action ->authorize(static::getResource()::canRestore($this->getRecord())); } protected function configureDeleteAction(DeleteAction $action): void { $resource = static::getResource(); $action ->authorize($resource::canDelete($this->getRecord())) ->successRedirectUrl($resource::getUrl('index')); } public function getTitle(): string | Htmlable { if (filled(static::$title)) { return static::$title; } return __('filament-panels::resources/pages/view-record.title', [ 'label' => $this->getRecordTitle(), ]); } public function form(Form $form): Form { return $form; } /** * @return array */ protected function getForms(): array { return [ 'form' => $this->form(static::getResource()::form( $this->makeForm() ->operation('view') ->disabled() ->model($this->getRecord()) ->statePath($this->getFormStatePath()) ->columns($this->hasInlineLabels() ? 1 : 2) ->inlineLabel($this->hasInlineLabels()), )), ]; } public function getFormStatePath(): ?string { return 'data'; } public function infolist(Infolist $infolist): Infolist { return static::getResource()::infolist( $infolist ->record($this->getRecord()) ->columns($this->hasInlineLabels() ? 1 : 2) ->inlineLabel($this->hasInlineLabels()), ); } protected function getMountedActionFormModel(): Model { return $this->getRecord(); } /** * @return array */ public function getWidgetData(): array { return [ 'record' => $this->getRecord(), ]; } }