【发布时间】:2018-11-05 13:06:38
【问题描述】:
我创建了一个模块,但链接不正确。
我的网站现在显示:
/store/2?0=/cgv
正确的链接应该是:
/store/2/cgv
为什么它不起作用?错误在哪里?
我应该在下面的代码中更改什么以获得链接?
<?php
namespace Drupal\commerce_agree_cgv\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 = "agree_cgv",
* label = @Translation("Agree CGV"),
* default_step = "review",
* )
*/
class AgreeCGV extends CheckoutPaneBase implements CheckoutPaneInterface {
/**
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$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' => 800,
]),
],
];
$link = Link::createFromRoute(
$this->t('the general terms and conditions of business'),
'entity.commerce_store.canonical',
['commerce_store' => $store_id, '/cgv'],
$attributes
)->toString();
$pane_form['cgv'] = [
'#type' => 'checkbox',
'#default_value' => FALSE,
'#title' => $this->t('I have read and accept @cgv.', ['@cgv' => $link]),
'#required' => TRUE,
'#weight' => $this->getWeight(),
];
return $pane_form;
}
}
【问题讨论】:
-
我对drupal一无所知,但这看起来在语法上是错误的:
['commerce_store' => $store_id, '/cgv']- 我想它应该是['commerce_store' => $store_id. '/cgv'](一个点而不是,,所以它会连接和不要添加另一个数组值。) -
@Jeff 谢谢,如果我用点替换逗号,我有这个错误
Symfony\Component\Routing\Exception\InvalidParameterException : Parameter "commerce_store" for route "entity.commerce_store.canonical" must match "\d+" ("3/cgv" given) to generate a corresponding URL. dans Drupal\Core\Routing\UrlGenerator->doGenerate() (ligne 204 de /var/www/www-domaine-com/web/core/lib/Drupal/Core/Routing/UrlGenerator.php). -
对我来说,drupal 说它应该是
['commerce_store' => $store_id],没有/cgv;这不是你想要的。恐怕我无法再提供任何帮助(不知道 drupal ......) -
你对路由
entity.commerce_store.canonical的定义是什么?听起来好像一开始就没有包含任何这样的额外参数。 -
@misorude api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/… J'ai trouvé ceci mais pas de réponse
标签: php drupal drupal-8 drupal-routes