-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEW][Features] Added support for field filters and request input values mutating. #376
Conversation
@unckleg This is great! Everything looks really good, just few minor things i want to change, just some code reorganization, nothing special. Will start a review and comment out the parts. Thanks a bunch! |
@unckleg This is great! Everything looks really good, just few minor things i want to change, just some code reorganization, nothing special. Will start a review and comment out the parts. Thanks! |
@kristijanhusak Good to hear that! I know that inital filterFields method calling from onFormCreate event is not place for that, I left it there just for showcase for now and maybe some parts of FilterResolver. I've planned many times to do PR and I somehow found time to do it yesterday. |
@kristijanhusak We could also start writing our Collection filters before Merging. |
* @return void | ||
*/ | ||
public function __construct(Form $form) { | ||
$this->form = $form; | ||
$this->filterFields(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to move this out of this event to the same place where the event is fired. I would like this event to be clean.
* @throws Exception\UnableToResolveFilterException | ||
* @throws Exception\InvalidInstanceException | ||
*/ | ||
public static function instance($filter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could remove some indentation here by returning early and returning the filter from the validate method. Here's how it could be written:
public static function instance($filter)
{
if (!is_string($filter)) {
return self::validateFilterInstance($filter);
}
if (class_exists($filter)) {
return self::validateFilterInstance(new $filter());
}
if ($filter = FilterResolver::resolveFromCollection($filter)) {
return self::validateFilterInstance($filter);
}
throw new UnableToResolveFilterException();
}
/**
* @param $filter
*
* @throws \Exception
*
* @return mixed
*/
private static function validateFilterInstance($filter)
{
if (!$filter instanceof FilterInterface) {
throw new InvalidInstanceException();
}
return $filter;
}
yeah you can do that also :) I finished reviewing, you can start :) |
@unckleg also, it would be great to write down some tests for this if you got time :) |
@kristijanhusak I'll write tests first for new functionalities and than starting with Collection filters. |
@kristijanhusak There 'll be small [CS] changes related to Filters, I'm thinking of simplifying the filter class names or aliases (StringToLower -> Lowercase, StringToUpper -> Uppercase, StringTrim -> Trim) maybe.. Also there should be some method & property for storing unmutated/pre-filtered field values. Some suggestions ? |
@unckleg yeah those names and aliases look fine. Both are ok if you ask me, it's up to you to choose. Storing original value would be great, in case there is a need to get it. Everything looks ok so far, you can add that original value stuff and choose the final naming. After that, we can merge this in :) |
Renamed few Collection filter classes
@kristijanhusak Finished everything planned for this commit i think you can merge it now. Todo:
|
@unckleg Thanks, everything looks great! Yeah some documentation would be great for this. Docs are on the Merging this to master. Won't release new version yet, but probably soon. Thanks a lot! |
@kristijanhusak Great! |
I've implemented something similary to Zend form filters, so now developers can filter data that is passed through Form.
Added:
Kris\LaravelFormBuilder\Fields\FormField:
Kris\Form:
Kris\LaravelFormBuilder\Events\AfterFormCreation
So now you can bind filters/filter to form field like this:
Modify fields:
And if you e.g
StringToUpper
filter for field name and you passed in post this value: "some string"the value you'll get in request is mutated. "SOME STRING".