我试图将CSS类添加到Drupal中的特定消息中,该消息在订阅mailchimp列表时成功输出,这是提交功能的代码:
public function submitForm(array &$form, FormStateInterface $form_state) {
global $base_url;
$list_details = mailchimp_get_lists($this->signup->mc_lists);
$subscribe_lists = array();
// Filter out blank fields so we don't erase values on the Mailchimp side.
$mergevars = array_filter($form_state->getValue('mergevars'));
$email = $mergevars['EMAIL'];
$mailchimp_lists = $form_state->getValue('mailchimp_lists');
// If we only have one list we won't have checkbox values to investigate.
if (count(array_filter($this->signup->mc_lists)) == 1) {
$subscribe_lists[0] = array(
'subscribe' => reset($this->signup->mc_lists),
'interest_groups' => isset($mailchimp_lists['interest_groups']) ? $mailchimp_lists['interest_groups'] : NULL,
);
}
else {
// We can look at the checkbox values now.
foreach ($mailchimp_lists as $list) {
if ($list['subscribe']) {
$subscribe_lists[] = $list;
}
}
}
$successes = array();
// Loop through the selected lists and try to subscribe.
foreach ($subscribe_lists as $list_choices) {
$list_id = $list_choices['subscribe'];
$interests = isset($list_choices['interest_groups']) ? $list_choices['interest_groups'] : array();
if (isset($this->signup->settings['safe_interest_groups']) && $this->signup->settings['safe_interest_groups']) {
$current_status = mailchimp_get_memberinfo($list_id, $email);
if (isset($current_status->interests)) {
$current_interests = array();
foreach ($current_status->interests as $id => $selected) {
if ($selected) {
$current_interests[$id] = $id;
}
}
$interests[] = $current_interests;
}
}
$result = mailchimp_subscribe($list_id, $email, $mergevars, $interests, $this->signup->settings['doublein']);
if (empty($result)) {
drupal_set_message(t('There was a problem with your newsletter signup to %list.', array(
'%list' => $list_details[$list_id]->name,
)), 'warning');
}
else {
$successes[] = $list_details[$list_id]->name;
}
}
if (count($successes) && strlen($this->signup->settings['confirmation_message'])) {
drupal_set_message($this->signup->settings['confirmation_message'], 'status');
}
$destination = $this->signup->settings['destination'];
if (empty($destination)) {
$destination_url = Url::fromRoute('<current>');
}
else {
$destination_url = Url::fromUri($base_url . '/' . $this->signup->settings['destination']);
}
$form_state->setRedirectUrl($destination_url);
}
我对更改此部分特别感兴趣:
if (count($successes) && strlen($this->signup->settings['confirmation_message'])) {
drupal_set_message($this->signup->settings['confirmation_message'], 'status');
}
我想添加一个仅针对此确认消息而非所有消息输出的类。我已经尝试了几件事:
根据一些相关的问答,我尝试编辑上面的“状态”部分以在其中添加一个类:“状态conf”或“状态,conf”,这两项都不起作用,唯一接受的值是“状态”,“警告”和“错误”,其他值不会转换。
我也尝试过:
if(count($ successes)&& strlen($ this-> signup-> settings ['confirmation_message'])){ drupal_set_message(''。$ this-> signup-> settings ['confirmation_message']。'','状态');
此选项不添加标记,而只是将其输出为字符串:
"<div class="conf">Our confirmation message</div>"
有什么建议吗?
答案 0 :(得分:0)
树枝模板用于输出html消息。
为什么documentation建议'type'参数只有3个选项,我不知道,但这是错误的。状态消息就像其他任何可输出的(是一个单词?)一样。
添加自己的课程,例如import $ from "jquery";
let newobject = $.extend(true, {}, object);
确实有效,但该类(使用经典主题模板时)将为drupal_set_message('Our confirmation message', 'conf');
。
对于“经典”主题,消息模板位于“ core / themes / classy / templates / misc / status-messages.html.twig”,如下所示:
messages--conf
要覆盖它,只需将自己的“ status-messages.html.twig”添加到主题(MY_THEME / templates / misc / status-messages.html.twig)并根据需要进行更改。