class AgreeTerms in Commerce Agree Terms 8
Provides the completion message pane.
Plugin annotation
@CommerceCheckoutPane(
id = "agree_terms",
label = @Translation("Agree to the terms and conditions"),
default_step = "review",
)
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\commerce_agree_terms\Plugin\Commerce\CheckoutPane\AgreeTerms 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 AgreeTerms
File
- src/
Plugin/ Commerce/ CheckoutPane/ AgreeTerms.php, line 20
Namespace
Drupal\commerce_agree_terms\Plugin\Commerce\CheckoutPaneView source
class AgreeTerms extends CheckoutPaneBase implements CheckoutPaneInterface {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'nid' => NULL,
'link_text' => 'Terms and Conditions',
'prefix_text' => 'I agree with the %terms',
'invalid_text' => 'You must agree with the %terms before continuing',
'new_window' => 1,
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationSummary() {
$prefix = $this->configuration['prefix_text'];
$link_text = $this->configuration['link_text'];
$invalid_text = $this->configuration['invalid_text'];
$new_window = $this->configuration['new_window'];
$nid = $this->configuration['nid'];
$summary = '';
if (!empty($prefix)) {
$summary = $this
->t('Prefix text: @text', [
'@text' => $prefix,
]) . '<br/>';
}
if (!empty($link_text)) {
$summary .= $this
->t('Link text: @text', [
'@text' => $link_text,
]) . '<br/>';
}
if (!empty($invalid_text)) {
$summary .= $this
->t('Error text: @text', [
'@text' => $invalid_text,
]) . '<br/>';
}
if (!empty($window_target)) {
$window_text = $new_window === 1 ? $this
->t('New window') : $this
->t('Same window');
$summary .= $this
->t('Window opens in: @opens', [
'@text' => $window_text,
]) . '<br/>';
}
if (!empty($nid)) {
$node = Node::load($nid);
if ($node) {
$summary .= $this
->t('Terms page: @title', [
'@title' => $node
->getTitle(),
]);
}
}
return $summary;
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['prefix_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Prefix text'),
'#default_value' => $this->configuration['prefix_text'],
];
$form['link_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Link text'),
'#default_value' => $this->configuration['link_text'],
'#required' => TRUE,
];
$form['invalid_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Invalid text'),
'#default_value' => $this->configuration['invalid_text'],
];
$form['new_window'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Open window link in new window'),
'#default_value' => $this->configuration['new_window'],
];
if ($this->configuration['nid']) {
$node = Node::load($this->configuration['nid']);
}
else {
$node = NULL;
}
$form['nid'] = [
'#type' => 'entity_autocomplete',
'#target_type' => 'node',
'#default_value' => $node,
'#required' => TRUE,
];
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['prefix_text'] = $values['prefix_text'];
$this->configuration['link_text'] = $values['link_text'];
$this->configuration['invalid_text'] = $values['invalid_text'];
$this->configuration['new_window'] = $values['new_window'];
$this->configuration['nid'] = $values['nid'];
}
}
/**
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$prefix_text = $this->configuration['prefix_text'];
$link_text = $this->configuration['link_text'];
$nid = $this->configuration['nid'];
if ($nid) {
$node = Node::load($nid);
$attributes = [];
if ($this->configuration['new_window']) {
$attributes = [
'attributes' => [
'target' => '_blank',
],
];
}
$link = Link::createFromRoute($this
->t($link_text), 'entity.node.canonical', [
'node' => $nid,
], $attributes)
->toString();
if ($prefix_text) {
$pane_form['terms_and_conditions'] = [
'#type' => 'checkbox',
'#default_value' => FALSE,
'#title' => $this
->t($prefix_text, [
'%terms' => $link,
]),
'#required' => TRUE,
'#weight' => $this
->getWeight(),
];
}
else {
$pane_form['terms_and_conditions'] = [
'#type' => 'checkbox',
'#default_value' => FALSE,
'#title' => $link,
'#required' => TRUE,
'#weight' => $this
->getWeight(),
];
}
}
return $pane_form;
}
/**
* {@inheritdoc}
*/
public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
$values = $form_state
->getValue($pane_form['#parents']);
if (!$values['terms_and_conditions']) {
$form_state
->setError($pane_form, $this->configuration['invalid_text']);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AgreeTerms:: |
public | function |
Form constructor. Overrides CheckoutPaneBase:: |
|
AgreeTerms:: |
public | function |
Builds a summary of the pane configuration. Overrides CheckoutPaneBase:: |
|
AgreeTerms:: |
public | function |
Builds the pane form. Overrides CheckoutPaneInterface:: |
|
AgreeTerms:: |
public | function |
Gets default configuration for this plugin. Overrides CheckoutPaneBase:: |
|
AgreeTerms:: |
public | function |
Form submission handler. Overrides CheckoutPaneBase:: |
|
AgreeTerms:: |
public | function |
Validates the pane form. Overrides CheckoutPaneBase:: |
|
CheckoutPaneBase:: |
protected | property | The parent checkout flow. | |
CheckoutPaneBase:: |
protected | property | The entity type manager. | |
CheckoutPaneBase:: |
protected | property | The current order. | |
CheckoutPaneBase:: |
public | function |
Builds a summary of the pane values. Overrides CheckoutPaneInterface:: |
3 |
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 |
Determines whether the pane is visible. Overrides CheckoutPaneInterface:: |
4 |
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 |
Handles the submission of an pane form. Overrides CheckoutPaneInterface:: |
7 |
CheckoutPaneBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
CheckoutPaneBase:: |
public | function |
Constructs a new CheckoutPaneBase object. Overrides PluginBase:: |
6 |
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. |