如何更改模式窗口的标题?

时间:2018-11-07 02:29:07

标签: php modal-dialog drupal-modules drupal-8

我有一个显示模式窗口的链接。

当我单击它时,它会在模式窗口“ Array”的标题中标记。

如何自定义标题?

这是我的Drupal模块:

/src/Plugin/Commerce/CheckoutPane/MarketplaceTermsAndConditions.php:

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.crash.air");
launchIntent.putExtra("pkgnme", "com.awesomeapp.com")

if (launchIntent != null) 
   startActivity(launchIntent); 
else 
   // beta app not found do nothing or something else

commerce_marketplace_terms_and_conditions.info.yml:

<?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;
  }

}

commerce_marketplace_terms_and_conditions.module:

name: Commerce Marketplace Terms and Conditions
description: Commerce checkout pane with a checkbox linked to your custom Marketplace Terms and Conditions page.
type: module
core: 8.x
package: Commerce (contrib)
dependencies:
  - commerce:commerce_checkout

这是当前模式窗口的屏幕截图:

enter image description here

2 个答案:

答案 0 :(得分:0)

只需在t()函数中为该窗口编写所需的标题。

答案 1 :(得分:0)

我正在使用Drupal 8.8.4。

您可以按照Berend de Boer的here所述,将类添加到模式中来使用CSS。

然后使用该类隐藏模式标题元素,并使用CSS :: before选择器添加自定义标题。

这利用了两个现有的Drupal核心类 .ui-dialog-title ui.dialog-titlebar。

诚然,将内容和样式混合在一起不是最佳实践。但这是一个简单,即时且可靠的解决方案,与到目前为止我在此Drupal错误中所发现的相比。

HTML

`<a class="use-ajax" data-dialog-options="{&quot;width&quot;:400, &quot;dialogClass&quot;: &quot;your-modal-class&quot;}" data-dialog-type="dialog" href="/your-awesome-modal">Tap here to see my awesome modal</a>`

CSS

.your-modal-class .ui-dialog-title {
  display: none;   /*To hide "Array" in title of modal, a known Drupal bug*/
}
.your-modal-class .ui-dialog-titlebar::before {
  content: "Your Title Here";
}