You are here

class ContactInformation in Commerce Core 8.2

Provides the contact information pane.

Plugin annotation


@CommerceCheckoutPane(
  id = "contact_information",
  label = @Translation("Contact information"),
  default_step = "order_information",
  wrapper_element = "fieldset",
)

Hierarchy

Expanded class hierarchy of ContactInformation

File

modules/checkout/src/Plugin/Commerce/CheckoutPane/ContactInformation.php, line 17

Namespace

Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane
View source
class ContactInformation extends CheckoutPaneBase implements CheckoutPaneInterface {

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'double_entry' => FALSE,
    ] + parent::defaultConfiguration();
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationSummary() {
    if (!empty($this->configuration['double_entry'])) {
      $summary = $this
        ->t('Require double entry of email: Yes');
    }
    else {
      $summary = $this
        ->t('Require double entry of email: No');
    }
    return $summary;
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);
    $form['double_entry'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Require double entry of email'),
      '#description' => $this
        ->t('Forces anonymous users to enter their email in two consecutive fields, which must have identical values.'),
      '#default_value' => $this->configuration['double_entry'],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::submitConfigurationForm($form, $form_state);
    if (!$form_state
      ->getErrors()) {
      $values = $form_state
        ->getValue($form['#parents']);
      $this->configuration['double_entry'] = !empty($values['double_entry']);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function isVisible() {

    // Show the pane only for guest checkout.
    return empty($this->order
      ->getCustomerId());
  }

  /**
   * {@inheritdoc}
   */
  public function buildPaneSummary() {
    return [
      '#plain_text' => $this->order
        ->getEmail(),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
    $pane_form['email'] = [
      '#type' => 'email',
      '#title' => $this
        ->t('Email'),
      '#default_value' => $this->order
        ->getEmail(),
      '#required' => TRUE,
    ];
    if ($this->configuration['double_entry']) {
      $pane_form['email_confirm'] = [
        '#type' => 'email',
        '#title' => $this
          ->t('Confirm email'),
        '#default_value' => $this->order
          ->getEmail(),
        '#required' => TRUE,
      ];
    }
    return $pane_form;
  }

  /**
   * {@inheritdoc}
   */
  public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
    $values = $form_state
      ->getValue($pane_form['#parents']);
    if ($this->configuration['double_entry'] && $values['email'] != $values['email_confirm']) {
      $form_state
        ->setError($pane_form, $this
        ->t('The specified emails do not match.'));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
    $values = $form_state
      ->getValue($pane_form['#parents']);
    $this->order
      ->setEmail($values['email']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CheckoutPaneBase::$checkoutFlow protected property The parent checkout flow.
CheckoutPaneBase::$entityTypeManager protected property The entity type manager.
CheckoutPaneBase::$order protected property The current order.
CheckoutPaneBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
CheckoutPaneBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 7
CheckoutPaneBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
CheckoutPaneBase::getDisplayLabel public function Gets the pane display label. Overrides CheckoutPaneInterface::getDisplayLabel
CheckoutPaneBase::getId public function Gets the pane ID. Overrides CheckoutPaneInterface::getId
CheckoutPaneBase::getLabel public function Gets the pane label. Overrides CheckoutPaneInterface::getLabel
CheckoutPaneBase::getStepId public function Gets the pane step ID. Overrides CheckoutPaneInterface::getStepId
CheckoutPaneBase::getWeight public function Gets the pane weight. Overrides CheckoutPaneInterface::getWeight
CheckoutPaneBase::getWrapperElement public function Gets the pane wrapper element. Overrides CheckoutPaneInterface::getWrapperElement
CheckoutPaneBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
CheckoutPaneBase::setOrder public function Sets the current order. Overrides CheckoutPaneInterface::setOrder
CheckoutPaneBase::setStepId public function Sets the pane step ID. Overrides CheckoutPaneInterface::setStepId
CheckoutPaneBase::setWeight public function Sets the pane weight. Overrides CheckoutPaneInterface::setWeight
CheckoutPaneBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
CheckoutPaneBase::__construct public function Constructs a new CheckoutPaneBase object. Overrides PluginBase::__construct 6
ContactInformation::buildConfigurationForm public function Form constructor. Overrides CheckoutPaneBase::buildConfigurationForm
ContactInformation::buildConfigurationSummary public function Builds a summary of the pane configuration. Overrides CheckoutPaneBase::buildConfigurationSummary
ContactInformation::buildPaneForm public function Builds the pane form. Overrides CheckoutPaneInterface::buildPaneForm
ContactInformation::buildPaneSummary public function Builds a summary of the pane values. Overrides CheckoutPaneBase::buildPaneSummary
ContactInformation::defaultConfiguration public function Gets default configuration for this plugin. Overrides CheckoutPaneBase::defaultConfiguration
ContactInformation::isVisible public function Determines whether the pane is visible. Overrides CheckoutPaneBase::isVisible
ContactInformation::submitConfigurationForm public function Form submission handler. Overrides CheckoutPaneBase::submitConfigurationForm
ContactInformation::submitPaneForm public function Handles the submission of an pane form. Overrides CheckoutPaneBase::submitPaneForm
ContactInformation::validatePaneForm public function Validates the pane form. Overrides CheckoutPaneBase::validatePaneForm
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.