class ContactSubscription in Mailchimp E-Commerce 8
Provides the subscription information pane.
Plugin annotation
@CommerceCheckoutPane(
id = "subscription_information",
label = @Translation("Subscription information"),
default_step = "order_information",
wrapper_element = "fieldset",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase implements CheckoutPaneInterface, ContainerFactoryPluginInterface
- class \Drupal\mailchimp_ecommerce_commerce\Plugin\Commerce\CheckoutPane\ContactSubscription implements CheckoutPaneInterface
- class \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase implements CheckoutPaneInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ContactSubscription
File
- modules/
mailchimp_ecommerce_commerce/ src/ Plugin/ Commerce/ CheckoutPane/ ContactSubscription.php, line 19
Namespace
Drupal\mailchimp_ecommerce_commerce\Plugin\Commerce\CheckoutPaneView source
class ContactSubscription extends CheckoutPaneBase implements CheckoutPaneInterface {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'label' => 'Subscribe to our newsletter',
'review' => 0,
'review_label' => 'Subscribe to newsletter:',
'review_label_on' => 'Yes',
'review_label_off' => 'No',
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationSummary() {
$summary = '';
if (!empty($this->configuration['label'])) {
$summary .= $this
->t('Label: @text', [
'@text' => $this->configuration['label'],
]) . '<br/>';
}
if (isset($this->configuration['review'])) {
$text = $this->configuration['review'] == 1 ? $this
->t('Yes') : $this
->t('No');
$summary .= $this
->t('Display in review step: @text', [
'@text' => $text,
]) . '<br/>';
}
if (!empty($this->configuration['review_label'])) {
$summary .= $this
->t('Review label: @text', [
'@text' => $this->configuration['review_label'],
]) . '<br/>';
}
if (!empty($this->configuration['review_label_on'])) {
$summary .= $this
->t('Review label on: @text', [
'@text' => $this->configuration['review_label_on'],
]) . '<br/>';
}
if (!empty($this->configuration['review_label_off'])) {
$summary .= $this
->t('Review label off: @text', [
'@text' => $this->configuration['review_label_off'],
]) . '<br/>';
}
return $summary;
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form = parent::buildConfigurationForm($form, $form_state);
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#default_value' => $this->configuration['label'],
];
$form['review'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display in review step'),
'#default_value' => $this->configuration['review'],
];
$form['review_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Review label'),
'#default_value' => $this->configuration['review_label'],
];
$form['review_label_on'] = [
'#type' => 'textfield',
'#title' => $this
->t('Review label on'),
'#default_value' => $this->configuration['review_label_on'],
];
$form['review_label_off'] = [
'#type' => 'textfield',
'#title' => $this
->t('Review label off'),
'#default_value' => $this->configuration['review_label_off'],
];
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['label'] = $values['label'];
$this->configuration['review'] = $values['review'];
$this->configuration['review_label'] = $values['review_label'];
$this->configuration['review_label_on'] = $values['review_label_on'];
$this->configuration['review_label_off'] = $values['review_label_off'];
}
}
/**
* {@inheritdoc}
*/
public function isVisible() {
$steps = $this->checkoutFlow
->getSteps();
return TRUE;
}
/**
* {@inheritdoc}
*/
public function buildPaneSummary() {
$pane_form = [];
if ($this->configuration['review'] == 1) {
// @TODO $form_state isn't available here. How can the value selected be
// retrieved?
$value_label = $this->configuration['review_label_on'];
$pane_form['subscription'] = [
'#type' => 'markup',
'#markup' => $this->configuration['review_label'] . ' ' . $value_label,
];
}
return $pane_form;
}
/**
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$pane_form['subscription'] = [
'#type' => 'checkbox',
'#title' => $this->configuration['label'],
'#default_value' => '',
'#required' => FALSE,
];
return $pane_form;
}
/**
* {@inheritdoc}
*/
public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
}
/**
* {@inheritdoc}
*/
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
$values = $form_state
->getValue($pane_form['#parents']);
if ($values['subscription'] == 1) {
$customer = [];
$customer['email_address'] = $this->order
->getEmail();
if (!empty($customer['email_address'])) {
/* @var \Drupal\mailchimp_ecommerce\CustomerHandler $customer_handler */
$customer_handler = \Drupal::service('mailchimp_ecommerce.customer_handler');
$billing_profile = $this->order
->getBillingProfile();
$customer = $customer_handler
->buildCustomer($customer, $billing_profile);
$customer_handler
->addOrUpdateCustomer($customer);
module_load_include('module', 'mailchimp', 'mailchimp');
$list_id = mailchimp_ecommerce_get_list_id();
$merge_vars = [
'EMAIL' => $customer['email_address'],
'FNAME' => $customer['first_name'],
'LNAME' => $customer['last_name'],
];
mailchimp_subscribe($list_id, $customer['email_address'], $merge_vars);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CheckoutPaneBase:: |
protected | property | The parent checkout flow. | |
CheckoutPaneBase:: |
protected | property | The entity type manager. | |
CheckoutPaneBase:: |
protected | property | The current order. | |
CheckoutPaneBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
CheckoutPaneBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
7 |
CheckoutPaneBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane display label. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane ID. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane label. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane step ID. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane weight. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane wrapper element. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
CheckoutPaneBase:: |
public | function |
Sets the current order. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Sets the pane step ID. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Sets the pane weight. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
CheckoutPaneBase:: |
public | function |
Constructs a new CheckoutPaneBase object. Overrides PluginBase:: |
6 |
ContactSubscription:: |
public | function |
Form constructor. Overrides CheckoutPaneBase:: |
|
ContactSubscription:: |
public | function |
Builds a summary of the pane configuration. Overrides CheckoutPaneBase:: |
|
ContactSubscription:: |
public | function |
Builds the pane form. Overrides CheckoutPaneInterface:: |
|
ContactSubscription:: |
public | function |
Builds a summary of the pane values. Overrides CheckoutPaneBase:: |
|
ContactSubscription:: |
public | function |
Gets default configuration for this plugin. Overrides CheckoutPaneBase:: |
|
ContactSubscription:: |
public | function |
Determines whether the pane is visible. Overrides CheckoutPaneBase:: |
|
ContactSubscription:: |
public | function |
Form submission handler. Overrides CheckoutPaneBase:: |
|
ContactSubscription:: |
public | function |
Handles the submission of an pane form. Overrides CheckoutPaneBase:: |
|
ContactSubscription:: |
public | function |
Validates the pane form. Overrides CheckoutPaneBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |