Skip to content
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

Expand the commerce_profile_select form element with the ability to reuse profiles #760

Closed
wants to merge 1 commit into from

Conversation

bojanz
Copy link
Contributor

@bojanz bojanz commented Jul 12, 2017

Continuation of #631, done by czigor and mglaman.

…an: Expand the commerce_profile_select form element with the ability to reuse profiles
@bojanz bojanz mentioned this pull request Jul 12, 2017
*/
class ProfileSelect extends RenderElement {
class ProfileSelect extends FormElement {
Copy link
Contributor Author

@bojanz bojanz Jul 23, 2017

Choose a reason for hiding this comment

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

This is reverting the fix from #2857051.

Might have started by accident, since this PR is older than that fix.

Copy link

@ymhuang0808 ymhuang0808 left a comment

Choose a reason for hiding this comment

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

Support multiple form elements in the same form for commerce_shipping module

'wrapper' => $wrapper_id,
],
'#submit' => [[get_called_class(), 'ajaxSubmit']],
'#name' => 'edit_profile',

Choose a reason for hiding this comment

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

I'm testing the patch when enabling commerce_shipping module.

Because, the commerce_shipping also uses the ProfileSelect element, in checkout page, there are multiple submit buttons with same #name. If the edit_button element is clicked, the trigger element will be wrong.

In my testing, when I clicked the "Edit" button, the trigger element was the "Continue to review" button. However, the expected and correct trigger element should be "Edit" button. The problem may result from the same value of #name and more detail is in issue #2546700.

In order to prevent the situation, we should have a workaround for the issue to make the value of #name unique.
My rough implementation:

$form_name = (isset($element['#parents'])) ? implode('_', $element['#parents']) . '_' : '';
$form_name .= 'edit_profile';

And the value of the #name is $form_name.

'#suffix' => '</div>',
// Pass the id along to other methods.
'#wrapper_id' => $wrapper_id,
'#element_mode' => $form_state->get('element_mode') ?: 'view',

Choose a reason for hiding this comment

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

If the multiple ProfileSelect form elements exist in the same form (eg. in checkout page, the shipping info and billing info), the element_mode in $form_state should be separated by the form parents.

For example, commerce_shipping module is installed, and there are two form elements in the same checkout form page. Once a edit_button within shipping info (or payment info) is clicked, the same element_mode value in $form_state is set into edit by ajaxSubmit(). Therefore, #element_mode in shipping info and payment info are edit. It caused another form element in payment info doesn't contain edit_button.

Perhaps, the element mode name should be with the form parents.

$form_state->get('element_mode-' . $id_prefix . '-edit_button')

*/
public static function ajaxSubmit(array &$form, FormStateInterface $form_state) {
$triggering_element = $form_state->getTriggeringElement();
$form_state->set('element_mode', $triggering_element['#element_mode']);

Choose a reason for hiding this comment

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

As previous mention, the element_mode key in form state should be changed into:

    $parents = implode('-', $triggering_element['#parents']);
    $element_mode_name = 'element_mode-' . $parents;

    $form_state->set($element_mode_name, $triggering_element['#element_mode']);

@ymhuang0808
Copy link

Hi @bojanz I would like to enhance the PR, should I create a PR into 8.x-2.x or profile_reuse branch?

@mglaman
Copy link
Contributor

mglaman commented Aug 29, 2017

@ymhuang0808 hm, yeah that's the problem with Github. I'll wait to see what @bojanz says.

But to follow up: one of the main issues is that the element does not work if there are multiple elements on the same page. Correct?

@ymhuang0808
Copy link

@mglaman Yes. I'm tring to fix that.

@ymhuang0808
Copy link

ymhuang0808 commented Aug 31, 2017

@bojanz and @mglaman The enhancement for the PR is ready to review on fliegen@57c1117. Please take a look. I think I should create a new PR into profile_reuse branch.

The commit has a few changes:

  • Make the "Edit" button available in multiple form elements
  • If the value of address field is changed, it will create a new customer profile entity
  • Fix in edit mode, the address field is not changed with profile_selection
  • Add functional JavaScript tests for multiple form elements

BTW, in order to support the ProfileSelect, I also revised the commerce_shipping.

Thanks.

@bojanz
Copy link
Contributor Author

bojanz commented Jul 18, 2018

This PR is outdated, the issue has many updated patches.

@bojanz bojanz closed this Jul 18, 2018
@bojanz bojanz deleted the profile_reuse branch April 4, 2019 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants