Closed realtebo closed 2 years ago
Hello @realtebo I think it's reasonable to add some more extensibility to Filters if needed, but I think I didn't totally understood your usecase.
You have access to $crud
variable within your filter.blade.php
^ Backpack\CRUD\app\Library\CrudPanel\CrudPanel {#815 ▼
+model: App\Models\Monster {[#1773 ▶](http://backpack-demo.test/admin/monster#sf-dump-1866282529-ref21773)}
+route: "admin/monster"
+entity_name: "monster"
+entity_name_plural: "monsters"
+entry: null
#request: Illuminate\Http\Request {#42 ▶}
+query: Illuminate\Database\Eloquent\Builder {#1769 ▶}
#currentOperation: "list"
#settings: array:28 [▶]
}
By default there is no entry
in the ListOperation, but ofcourse you could be customizing that too.
You have the CRUD::setOperationSettitng()
and CRUD::getOperationSetting()
to configure your crud operations.
Also, wouldn't CRUD::filter([...filter_options],$values .... )->someCustomAttribute('value')
work ?
Let me know. Cheers
I ask you about this
Also, wouldn't CRUD::filter([...filter_options],$values .... )->someCustomAttribute('value') work ?
Where is this documented !?
Can you make an example?
Hello @realtebo
You are rigth this is not documented, I've just looked at the source code at that time and follow-up with a solution for you:
// -------------
// MAGIC METHODS
// -------------
/**
* If a developer calls a method that doesn't exist, assume they want:
* - $this->options['whatever'] to be set to that value;
* - that filter be updated inside the global CrudPanel object;.
*
* Eg: type('number') will set the "type" attribute to "number"
*
* @param string $method The method being called that doesn't exist.
* @param array $parameters The arguments when that method was called.
* @return CrudFilter
*/
public function __call($method, $parameters)
{
$this->setOptionValue($method, $parameters[0]);
return $this->save();
}
I've sent now a PR to docs to document this feature.
I will be closing this for now as I think the solution we have is enough for most of the projects, we will revisit this if needed in the future.
Thanks for pointing out this issue 🙏
Cheers
🤯 I had no idea that worked either 😅 Great job finding this, Pedro!
type('number') will set the "type" attribute to "number"
I already known this, but my request is to pass CUSTOM options to crud filter to be used when customizing filter's blade
a do not want a new attribute, but I need to pass some values to a filter blade
Feature Request
What's the feature you think Backpack should have?
We ask you kindly to add a parameter to filter object to allow, in case of customization, to pass some extra fields for extended configurability.
Our The goal is the follwing
I a specific case we need to pass the current crud entry to the filter view and the id of a sibling filter to create the dependant dropDown
We would like to have the filter class inaltered, without the need to extend it I mean, and be able to pass in a "customOptions" entry some data like "currentCrudEntry", or "dependantSelector'
So changing ONLY the filter view we could have an extended configurability.
A reflection
other add* function (for columns and fields) are plain arrays. So we can freely happend whatever we need the filter is a class and so we cannot append custom properties because they are simply ignored by the class and that custom properties are not passed down to the blade view
Have you already implemented a prototype solution, for your own project?
No
Do you see this as a core feature or an add-on?
Yes. It's also not a breaking change.