plugin icon indicating copy to clipboard operation
plugin copied to clipboard

[Feature Request /Filament support]: Hint Evaluated Closure Parameters

Open freshleafmedia opened this issue 5 months ago • 1 comments

Feature Description

Filament has a lot of methods which accept a closure to be evaluated later. The trouble is that the developer is required to remember the names of the possible parameters the closure accepts.

It would be awesome if they could be hinted.

For example the $state parameter here:

TextInput::make()
    ->formatStateUsing(function ($state): string {})

When the closure is evaluated Filament inspects the closure parameters using reflection and tries to resolve them to concrete values. For The simplified call chain goes like this:

  • EvaluatesClosures::evaluate(function ($state): string {}) - src
  • EvaluatesClosures::resolveClosureDependencyForEvaluation('state')
  • EvaluatesClosures::resolveDefaultClosureDependencyForEvaluationByName('state')
  • Component::resolveDefaultClosureDependencyForEvaluationByName('state') - src - this returns the value for $state and it's injected into the closure

There are a number of classes which implement resolveDefaultClosureDependencyForEvaluationByName, each defines a different list of special variables which can be injected.

Even if the list of hints wasn't context aware and just showed all possible options it would be a step forward.

freshleafmedia avatar Aug 06 '25 16:08 freshleafmedia

#Thank you for taking the time to share your request! I've added it into internal feature tracker.

We can collect dependency names from match() calls within component class hierarchy, at least for default components and their descendants, if they will use same match($propertyName)-> syntax, but I doubt we can do anything more complex or requiring runtime evaluations, will this help?

gorbunov avatar Aug 06 '25 17:08 gorbunov