-
Notifications
You must be signed in to change notification settings - Fork 50
fixxed #94 'Missing required failure message for CollectionInputFilter' issue #170
Conversation
@froschdesign Is there any updates relation to pull request? |
@ruzann |
@ruzann |
@froschdesign can you please review? |
@froschdesign all your notes fixed, please check again, when you have a time. |
@froschdesign is there any news from this pull request? Thanks. |
@ruzann function getNotEmptyValidator()
{
if ($this->notEmptyValidator === null) {
$this->notEmptyValidator = new NotEmpty();
}
return $this->notEmptyValidator;
}
function setNotEmptyValidator($notEmptyValidator);
function prepareRequiredValidationFailureMessage(); The default error message already exists and you can replace the validator with your own. (Yes, we do not use the validator for validation, but we allow a translation of the error message with the standard way.) What do you think? /cc @malukenho @rkeet @newdevonair Sorry for the late response and the short review. My focus is currently on the documentation, website and zend-navigation. |
I would suggest same as @froschdesign review: own getter/setter for storing NotEmpty instance. Otherwise seems alright to me, apart from tests not passing ;) |
@froschdesign I fixed your notes, please check again. |
Hi guys, do you have any updates related this issue? Is it ready to merge or have any other improvement? |
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.
Honestly, this looks really convoluted. If I'm reading this correctly:
- You allow injecting a string message for the purposes of seeding a
NotEmpty
validator - You manually test if the collection is empty, and, if so:
- grab the
NotEmpty
validator - Grab its
NOT_EMPTY
template to use as a message - Optionally translate the message, if the validator has a translator attached
- Return that message
- grab the
It seems like it would make more sense to:
- Allow setting a message template for when the collection is empty
- Allow optionally setting a translator, to allow translating the above message
- Use each of the above when the collection is empty to populate the validation failure messages
Alternately, we should allow specifying a validator and/or validator chain at the top level for checking the status of the collection, prior to attempting to validate the members of the collection.
This one! (See my example with pseudo code above.) |
@weierophinney, @froschdesign is there any news? |
@ruzann Please see the feedback above - @froschdesign and I feel that the approach outlined here is convoluted, and inconsistent with the architecture. Adding a validator chain specific to the collection input filter as an entity would make more sense. If you can refactor to that approach, we can review again. |
src/Factory.php
Outdated
@@ -319,6 +319,9 @@ public function createInputFilter($inputFilterSpecification) | |||
if (isset($inputFilterSpecification['required'])) { | |||
$inputFilter->setIsRequired($inputFilterSpecification['required']); | |||
} | |||
if (isset($inputFilterSpecification['messageRequired'])) { |
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.
Please use required_message
for consistency.
@froschdesign is there any news? |
@ruzann In the meantime, just use your own fork. |
This patch modifies the `CollectionInputFilter` to allow injecting a `Zend\Validator\NotEmpty` instance. When the collection is marked "required", but receives an empty data set, it will use that validator to provide a validation failure message. (If no validator was set, it lazy-loads one.) When using factory-based collections, you may now also provide a `required_message` key as a sibling to `required`; when set, this message will be used in place of the default `NotEmpty` validation error message.
- Combine conditionals, as there is only one combination that has a meaning - Use a ternary to allow removing a transient variable
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.
The changes look much better, @ruzann .
I'm going to do the following:
- Rebase off of develop
- Squash your commits (50 is excessive here!)
- Split the tests up to demonstrate the behaviors we're interested in
- Push a few additional changes I noticed during review
Then we can 🚢!
- Lazy-loads a NotEmpty validator if none provided. - Allows composing a NotEmpty validator. - Uses the message from a composed NotEmpty validator when validating a required, but empty, collection. - Factory will use the `required_message` key to seed the `NotEmpty` validator of a collection.
4ab9dec
to
9fd3546
Compare
Thanks, @ruzann! |
Added default message to display when a collection is required.
Added mechanism for setting a custom "required" message.
Updated factorie to allow setting that message.