Commit cea92ecf authored by Sut3kh's avatar Sut3kh Committed by Greg Knaddison
Browse files

Issue #2987060 by Sut3kh, andypost, greggles, Anybody, lkacenja, jnrfred:...

Issue #2987060 by Sut3kh, andypost, greggles, Anybody, lkacenja, jnrfred: Commerce 2 Completion Registration checkout pane
parent eb5b42a5
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\email_registration\Plugin\Commerce\CheckoutPane;

use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CompletionRegister;
use Drupal\Core\Form\FormStateInterface;

/**
 * Provides the registration pane without username.
 *
 * Assumes email_registration is enabled.
 *
 * @CommerceCheckoutPane(
 *   id = "email_registration_completion_registration",
 *   label = @Translation("Email registration guest registration after checkout"),
 * )
 */
class EmailRegistrationCompletionRegistration extends CompletionRegister {

  /**
   * {@inheritdoc}
   */
  public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
    $pane_form = parent::buildPaneForm($pane_form, $form_state, $complete_form);

    // Set the name as per email_registration_form_user_register_form_alter().
    $pane_form['name'] = [
      '#type' => 'hidden',
      '#value' => 'email_registration_' . user_password(),
    ];

    // Try and help password managers.
    // https://www.chromium.org/developers/design-documents/form-styles-that-chromium-understands
    $pane_form['email'] = [
      '#type' => 'textfield',
      '#value' => $this->order->getEmail(),
      '#attributes' => [
        'autocomplete' => 'username',
      ],
      '#wrapper_attributes' => [
        'style' => 'display: none;',
      ],
    ];

    return $pane_form;
  }

}