我有一个带有Drupal Commerce 2.14模块的Drupal 8.7网站。
我创建了一个市场(同一站点上有多个商人)。在商店类型中,我创建了一个机器名称为field_terms_and_conditions
的“文本(长格式)”字段。
在此字段中,商人写下他的一般销售条件,客户在订购过程中必须接受。
当客户在多个商店中订购时,这将创建多个购物车(商店名称显示在每个购物车上方)。效果很好。现在,Drupal Commerce正在处理地址簿,订单非常快。
当前,我已经创建了一个视图,该视图在页面上显示字段field_terms_and_conditions
的内容。我还创建了一个自定义模块,以在模式窗口中显示一个带有常规销售条件链接的复选框。
我想在模式窗口中直接渲染字段field_terms_and_conditions
,而不使用视图。该怎么做?
/src/Plugin/Commerce/CheckoutPane/MarketplaceTermsAndConditions.php
:
<?php
namespace Drupal\commerce_marketplace_terms_and_conditions\Plugin\Commerce\CheckoutPane;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Form\FormStateInterface;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* 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;
}
}