Php如何在链接的末尾添加元素? [英] Php how to add an element at the end of the link ?

查看:82
本文介绍了Php如何在链接的末尾添加元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Drupal 8.6和Commerce 2.10的网站



如何在网址的末尾添加一个元素?



使用下面的自定义模块,当前路径为:



I have a site with Drupal 8.6 and Commerce 2.10

How to add an element at the end of the url ?

With the custom module below, the current path is :

https://www.domaine.com/store/3





在下面的链接中,我想在链接的末尾添加/ cgv





In the link below, I want to add at the end of the link /cgv

https://www.domaine.com/store/3/cgv



这是我的自定义模块:




Here is my custom module :

<?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;
    
    /**
     * 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 = 3;
        $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],
          $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;
      }
    
    }





我尝试过:





What I have tried:

I think you have to add something to the line below, but I do not know what:




$link = Link::createFromRoute(
  $this->t('the general terms and conditions of business'),
  'entity.commerce_store.canonical',
  ['commerce_store' => $store_id],
  $attributes
)->toString();







If I change with ['commerce_store' => $store_id, '/cgv'] the link is not corect /store/3?0=/cgv





谁能帮帮我?



如果我更换:





Who can help me ?

If I replace :

['commerce_store' => $store_id, '/cgv'],





by:





by :

['commerce_store' => $store_id. '/cgv'],





我的日志中出现此错误:





I have this error in my logs :

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).

推荐答案

pane_form,FormStateInterface
pane_form, FormStateInterface


form_state,array&
form_state, array &


complete_form){
complete_form) {


这篇关于Php如何在链接的末尾添加元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆