[Promotion] Use one autocomplete type to rule them all#7070
Conversation
| { | ||
| if (null === $value) { | ||
| return ''; | ||
| return null; |
There was a problem hiding this comment.
Are you sure about that change? I recall that according to symfony docs we should return empty string here.
There was a problem hiding this comment.
This is ResourceToIdentifier IMO it should not change type.
There was a problem hiding this comment.
I don't like it also, but remember that Symfony recommended that.
From DataTransformerInterface:
* This method must be able to deal with empty values. Usually this will
* be NULL, but depending on your implementation other empty values are
* possible as well (such as empty strings). The reasoning behind this is
* that value transformers must be chainable. If the transform() method
* of the first value transformer outputs NULL, the second value transformer
* must be able to process that value.
*
* By convention, transform() should return an empty string if NULL is
* passed.
By convention it should return empty string, but not sure why 😄
There was a problem hiding this comment.
There are some exceptions even in Symfony codebase:
BooleanToStringTransformerChoiceToValueTransformer
I guess the convention was made to overcome this bug: symfony/symfony#18357
There was a problem hiding this comment.
If Symfony returns null in some cases and null works for us and is more appropriate, I think we can ignore the convention 😆
| public function transform($productTaxon) | ||
| { | ||
| if (null === $productTaxon) { | ||
| return null; |
| $this->transform($productTaxon)->shouldReturn($taxon); | ||
| } | ||
|
|
||
| function it_returns_null_during_transform() |
There was a problem hiding this comment.
it_returns_null_during_transforming_null_value? As it seems like it does it every time 😄
| $this->reverseTransform($taxon)->shouldReturn($productTaxon); | ||
| } | ||
|
|
||
| function it_returns_null_during_reverse_transform() |
There was a problem hiding this comment.
it_returns_null_during_reverse_transforming_of_null_value
| $this->reverseTransform(null)->shouldReturn(null); | ||
| } | ||
|
|
||
| function it_throws_invalid_argument_exception_during_transforms() |
There was a problem hiding this comment.
it_throws_invalid_argument_exception_during_transformation_if_passed_value_is_invalid
| data-choice-value="{{ form.vars.choice_value }}" | ||
| data-criteria-type="{{ form.vars.remote_criteria_type }}" | ||
| data-criteria-name="{{ form.vars.remote_criteria_name }}" | ||
| > |
There was a problem hiding this comment.
Formatting doesn't look good here 😕
6e282e5 to
21059d2
Compare
21059d2 to
ee9e2e5
Compare
Resource auto complete configuration reference:
{{form(form, { 'remote_url': path('sylius_admin_ajax_product_index'), 'remote_criteria_type': 'contains', 'remote_criteria_name': 'search' })}}And that is it generic javascript will catch this and do the rest
Blocked by #6936