F
Filament2mo ago
adnn

Use same infolist as page and modal when needed?

I have a resource with a view page infolist. I also want to add an Action in some other panel that would just open a peek infolist modal from that resource, rather than going to the page or having to copy paste the infolist in the action how can i achieve this?
4 Replies
Dennis Koch
Dennis Koch2mo ago
Have a look at the code of the ViewAction. It's basically what you need, just without the switch for Page vs. Modal.
adnn
adnn2mo ago
Thank you, this seems to be what I'm looking for. But how do you properly reference the record from an outside resource? Currently I have this, which is outside the review resource,
Action::make('review')
->badge()
->icon('heroicon-c-link')
->url(fn ($record) => \App\Filament\Resources\ReviewResource::getUrl('view', ['record' => $reviewId]))
->openUrlInNewTab();
Action::make('review')
->badge()
->icon('heroicon-c-link')
->url(fn ($record) => \App\Filament\Resources\ReviewResource::getUrl('view', ['record' => $reviewId]))
->openUrlInNewTab();
Dennis Koch
Dennis Koch2mo ago
Where do you use that code? I think the actions have a ->record() method to pass in the record. But u thought you wanted the modal? You don’t need to use a whole action just for a link
adnn
adnn2mo ago
I am using it inside the AppServiceProvider, to extend the Ralph Media plugin Basically trying to add a button on each image in the media page, that will quickly open a view modal of it's parent Review, so you can see where each image is used.
public function boot(): void
{
Model::unguard();

MediaLibrary::registerMediaInfoInformationUsing(
function (array $information, MediaLibraryItem $mediaLibraryItem, MediaItemMeta $mediaItemMeta): array {

$reviewIds = DB::table('media_library_item_review')
->where('media_library_item_id', $mediaLibraryItem->getKey())
->pluck('review_id');

$reviewActions = [];

foreach ($reviewIds as $reviewId) {
$reviewActions["Used on ID " . $reviewId] = Actions\Action::make('review')
->badge()

->icon('heroicon-c-link')
->url(fn ($record) => \App\Filament\Resources\ReviewResource::getUrl('view', ['record' => $reviewId]))
->openUrlInNewTab();
}

return array_merge($information, $reviewActions);

});
public function boot(): void
{
Model::unguard();

MediaLibrary::registerMediaInfoInformationUsing(
function (array $information, MediaLibraryItem $mediaLibraryItem, MediaItemMeta $mediaItemMeta): array {

$reviewIds = DB::table('media_library_item_review')
->where('media_library_item_id', $mediaLibraryItem->getKey())
->pluck('review_id');

$reviewActions = [];

foreach ($reviewIds as $reviewId) {
$reviewActions["Used on ID " . $reviewId] = Actions\Action::make('review')
->badge()

->icon('heroicon-c-link')
->url(fn ($record) => \App\Filament\Resources\ReviewResource::getUrl('view', ['record' => $reviewId]))
->openUrlInNewTab();
}

return array_merge($information, $reviewActions);

});