awcodes / filament-tiptap-editor

A Rich Text Editor plugin for Filament Forms.
MIT License
251 stars 65 forks source link

Inject current Filament component in each preview blade file #320

Closed slovenianGooner closed 2 months ago

slovenianGooner commented 5 months ago

This pull request adds an additional param to the getPreview method to inject the current component (TiptapEditor) to each preview Blade file.

This enables the user to have access ie. to the current record when editing in the panel.

Example blade file:

@if ($image)
    <img src="/{{ $image }}" alt="{{ $caption }}"/>
    {{ $caption }}
@endif

{{ $component->getContainer()?->getRecord()?->id }}

The same possibility does not exist on rendered blade files, you have to find other ways of injecting the record ie. example with the app container.

awcodes commented 5 months ago

Was already working on this on the feat/pass-record-to-views branch. Had it mostly working but there is a n+1 issue with the approach when blocks are rendered on the front end.

slovenianGooner commented 5 months ago

Do you mean frontend - the "rendered" views?

awcodes commented 5 months ago

yes. hard to remember exactly what I ran into, but it was mostly working.

Can you give me an example of what you would need the record for in the preview / rendered views?

slovenianGooner commented 5 months ago

Specifically,

Spatie’s Laravel Media Library. I would access the record and the filter down the media by a custom property.

Like said, no issue on the rendered blade files, I have more control there

Lp, Lovro Papež

On Fri, 2 Feb 2024 at 16:24, Adam Weston @.***> wrote:

yes. hard to remember exactly what I ran into, but it was mostly working.

Can you give me an example of what you would need the record for in the preview / rendered views?

— Reply to this email directly, view it on GitHub https://github.com/awcodes/filament-tiptap-editor/pull/320#issuecomment-1924096178, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJTBHJQE5OHEHQUEXMTDJDYRUAMTAVCNFSM6AAAAABCUQ4PYKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRUGA4TMMJXHA . You are receiving this because you authored the thread.Message ID: @.***>