Call to a member function getInfolist() on null

I'm trying to create a custom Infolist action, but I'm getting the following error Call to a member function getInfolist() on null This is the action I've created
class CustomLinkAction extends Action
{
// use CanCustomizeProcess; // I added this because I thought it was needed but it didn't help

public static function getDefaultName(): ?string
{
return 'customLink';
}

protected function setUp(): void
{
parent::setUp();

// The following line throws the error. But anything that uses `$this` seems to throw the same error
$this->url($this->getRecord()->getCustomUrl());
}
}
class CustomLinkAction extends Action
{
// use CanCustomizeProcess; // I added this because I thought it was needed but it didn't help

public static function getDefaultName(): ?string
{
return 'customLink';
}

protected function setUp(): void
{
parent::setUp();

// The following line throws the error. But anything that uses `$this` seems to throw the same error
$this->url($this->getRecord()->getCustomUrl());
}
}
Solution:
closure maybe ```php $this->url(function ($record) { //... });...
Jump to solution
4 Replies
LeandroFerreira
LeandroFerreira12mo ago
I think getRecord() isn't available at this point
ChesterS
ChesterSOP12mo ago
It's before that actually. In the BelongsToInfolist trait, the method getComponent() returns null Not sure if I'm supposed to manually pass the component, but that doesn't sound right since the dafault Filament\Infolists\Components\Actions\Action works as expected. Maybe I'm missing something 🤔
Solution
LeandroFerreira
LeandroFerreira12mo ago
closure maybe
$this->url(function ($record) {
//...
});
$this->url(function ($record) {
//...
});
ChesterS
ChesterSOP12mo ago
Heh yeah I checked the other custom actions and that's how they do it.
Want results from more Discord servers?
Add your server