Commit d9b9af00 authored by daria.a's avatar daria.a Committed by greggles

Issue #2684153 by gnuget, chegor, john.money, daria.a: Invalid tokens

parent f5793622
......@@ -289,6 +289,7 @@ function comment_notify_comment_load($comments) {
* The comment entity.
*/
function _comment_notify_mailalert(CommentInterface $comment) {
module_load_include('inc', 'comment_notify', 'comment_notify');
$config = \Drupal::config('comment_notify.settings');
......@@ -338,7 +339,7 @@ function _comment_notify_mailalert(CommentInterface $comment) {
&& !empty($author->getEmail())
) {
$raw_values = $config->get('mail_templates.entity_author');
$token_data = ['comment' => $comment];
$token_data = ['comment' => $comment, 'node' => $node];
$message['subject'] = PlainTextOutput::renderFromHtml(\Drupal::token()->replace($raw_values['subject'], $token_data));
$message['body'] = \Drupal::token()->replace($raw_values['body'], $token_data);
......@@ -373,7 +374,7 @@ function _comment_notify_mailalert(CommentInterface $comment) {
}
$raw_values = $config->get('mail_templates.watcher');
$token_data = ['comment' => $comment, 'comment-subscribed' => $alert];
$token_data = ['comment' => $comment, 'node' => $node, 'comment-subscribed' => $alert];
$message['subject'] = PlainTextOutput::renderFromHtml(\Drupal::token()->replace($raw_values['subject'], $token_data));
$message['body'] = \Drupal::token()->replace($raw_values['body'], $token_data);
......
......@@ -8,11 +8,11 @@ enable_default:
entity_author: false
mail_templates:
watcher:
subject: '[site:name] :: new comment on [comment:node:title]'
subject: '[site:name] :: new comment on [node:title]'
body: |
Hi [comment-subscribed:author],
[comment:author] has commented on: "[comment:node:title]"
[comment:author] has commented on: "[node:title]"
----
[comment:title]
......@@ -33,9 +33,9 @@ mail_templates:
entity_author:
subject: '[site:name] :: new comment for your post'
body: |
Hi [comment:node:author],
Hi [node:author],
You have received a comment on: "[comment:node:title]"
You have received a comment on: "[node:title]"
----
[comment:title]
......@@ -47,7 +47,7 @@ mail_templates:
You will receive emails like this for all replies to your posts. You can
disable this by logging in and changing the settings on your user account at
[comment:node:author:edit-url].
[node:author:edit-url].
-- [site:name] team
[site:url]
......@@ -116,7 +116,7 @@ class CommentNotifySettings extends ConfigFormBase {
'#cols' => 80,
'#rows' => 15,
'#token_types' => [
'comment'
'comment', 'node'
],
'#element_validate' => ['token_element_validate'],
];
......@@ -133,15 +133,15 @@ class CommentNotifySettings extends ConfigFormBase {
'#cols' => 80,
'#rows' => 15,
'#token_types' => [
'comment'
'comment', 'node'
],
'#element_validate' => ['token_element_validate'],
];
$form['token_help'] = [
'#theme' => 'token_tree',
'#theme' => 'token_tree_link',
'#token_types' => [
'comment'
'comment', 'node'
],
];
......
<?php
namespace Drupal\Tests\comment_notify\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\comment\Tests\CommentTestTrait;
/**
* Tests for the comment_notify module.
*
* @group comment_notify
*/
class CommentNotifyConfigPageTest extends BrowserTestBase {
use CommentTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'comment_notify',
'node',
'comment',
'token',
];
/**
* Test that the config page is working.
*/
protected function setUp() {
parent::setUp();
// Create and login administrative user.
$admin_user = $this->drupalCreateUser(array('administer comment notify', 'administer permissions', 'administer comments'));
$this->drupalLogin($admin_user);
// Enable comment notify on this node.
$this->drupalCreateContentType([
'type' => 'article',
]);
$this->addDefaultCommentField('node', 'article');
}
/**
* Test to all the options are saved correctly.
*/
public function testConfigPage() {
// Check the default values are working.
$this->drupalGet("admin/config/people/comment_notify");
$this->submitForm([], 'Save configuration');
$this->assertSession()->responseContains('The configuration options have been saved.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment