I have created a small module to display an “Agree to Terms” link in the Drupal Commerce shopping tunnel.
This link displays the store’s condition page.
I want to display the rendered store entity instead of the conditions page. How to do this ?
I created in my type of store, a display named “Terms and conditions”. I want to make this display in a modal window when the user clicks on the link.
Here is my code :
https://git.drupalcode.org/sandbox/zenimagine-3082137
<?php
namespace Drupalcommerce_marketplace_terms_and_conditionsPluginCommerceCheckoutPane;
use DrupalComponentSerializationJson;
use DrupalCoreFormFormStateInterface;
use Drupalcommerce_checkoutPluginCommerceCheckoutPaneCheckoutPaneBase;
use Drupalcommerce_checkoutPluginCommerceCheckoutPaneCheckoutPaneInterface;
use DrupalCoreLink;
use DrupalCoreUrl;
/**
* Provides the completion message pane.
*
* @CommerceCheckoutPane(
* id = "marketplace_terms_and_conditions",
* label = @Translation("Marketplace Terms and Conditions"),
* default_step = "review",
* )
*/
class MarketplaceTermsAndConditions extends CheckoutPaneBase implements CheckoutPaneInterface {
/**
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$store_name = $this->order->getStore()->getName();
$store_id = $this->order->getStoreId();
$pane_form('#attached')('library')() = 'core/drupal.dialog.ajax';
$attributes = (
'attributes' => (
'class' => 'use-ajax',
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode((
'width' => 'auto'
)),
),
);
$link = Link::fromTextAndUrl(
$this->t('terms and conditions of the store "@store_name"', ('@store_name' => $store_name)),
Url::fromUri("internal:/store/$store_id/cgv", $attributes)
)->toString();
$pane_form('marketplace_terms_and_conditions') = (
'#type' => 'checkbox',
'#default_value' => FALSE,
'#title' => $this->t('I have read and accept @terms.', ('@terms' => $link)),
'#required' => TRUE,
'#weight' => $this->getWeight(),
);
return $pane_form;
}
}