Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Promotion] Use one autocomplete type to rule them all#7070

Closed
Arminek wants to merge 1 commit into
Sylius:masterfrom
Arminek:use-auto-complete-in-generic-js
Closed

[Promotion] Use one autocomplete type to rule them all#7070
Arminek wants to merge 1 commit into
Sylius:masterfrom
Arminek:use-auto-complete-in-generic-js

Conversation

@Arminek
Copy link
Copy Markdown
Contributor

@Arminek Arminek commented Dec 13, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? no
License MIT

Resource auto complete configuration reference:

->add('products', ResourceAutocompleteChoiceType::class, [
                'label' => 'sylius.form.promotion_filter.products',
                'multiple' => true,
                'required' => false,
                'choice_value' => 'id',
                'choice_name' => 'name',
                'resource' => 'sylius.product',
])
{{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

{
if (null === $value) {
return '';
return null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about that change? I recall that according to symfony docs we should return empty string here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ResourceToIdentifier IMO it should not change type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some exceptions even in Symfony codebase:

  • BooleanToStringTransformer
  • ChoiceToValueTransformer

I guess the convention was made to overcome this bug: symfony/symfony#18357

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return '';?

@pjedrzejewski pjedrzejewski added New Feature UX Issues and PRs aimed at improving User eXperience. labels Dec 13, 2016
$this->transform($productTaxon)->shouldReturn($taxon);
}

function it_returns_null_during_transform()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it_returns_null_during_reverse_transforming_of_null_value

$this->reverseTransform(null)->shouldReturn(null);
}

function it_throws_invalid_argument_exception_during_transforms()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }}"
>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting doesn't look good here 😕

@Arminek Arminek force-pushed the use-auto-complete-in-generic-js branch from 6e282e5 to 21059d2 Compare February 16, 2017 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

UX Issues and PRs aimed at improving User eXperience.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants