Commit f3772b13 authored by webchick's avatar webchick

Issue #2453143 by Wim Leers: CommentForm depends on configured field, but...

Issue #2453143 by Wim Leers: CommentForm depends on configured field, but doesn't associate that cache tag
parent e2d2b24e
......@@ -94,6 +94,10 @@ public function form(array $form, FormStateInterface $form_state) {
$form['#attributes']['data-user-info-from-browser'] = TRUE;
}
// Vary per role, because we check a permission above and attach an asset
// library only for authenticated users.
$form['#cache']['contexts'][] = 'user.roles';
// If not replying to a comment, use our dedicated page callback for new
// Comments on entities.
if (!$comment->id() && !$comment->hasParentComment()) {
......@@ -210,7 +214,12 @@ public function form(array $form, FormStateInterface $form_state) {
'#access' => $is_admin,
);
$form['#cache']['tags'] = Cache::mergeTags(isset($form['#cache']['tags']) ? $form['#cache']['tags'] : [], $config->getCacheTags());
$form['#cache']['tags'] = Cache::mergeTags(
isset($form['#cache']['tags']) ? $form['#cache']['tags'] : [],
$config->getCacheTags(),
// The form depends on the field definition.
$field_definition->getConfig($entity->bundle())->getCacheTags()
);
return parent::form($form, $form_state, $comment);
}
......
......@@ -37,7 +37,7 @@ protected function setUp() {
*/
function testAnonymous() {
$this->drupalLogin($this->adminUser);
$this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
$this->setCommentAnonymous(COMMENT_ANONYMOUS_MAYNOT_CONTACT);
$this->drupalLogout();
// Post anonymous comment without contact info.
......@@ -46,7 +46,7 @@ function testAnonymous() {
// Allow contact info.
$this->drupalLogin($this->adminUser);
$this->setCommentAnonymous('1');
$this->setCommentAnonymous(COMMENT_ANONYMOUS_MAY_CONTACT);
// Attempt to edit anonymous comment.
$this->drupalGet('comment/' . $anonymous_comment1->id() . '/edit');
......@@ -59,6 +59,7 @@ function testAnonymous() {
$this->assertTrue($this->commentContactInfoAvailable(), 'Contact information available.');
// Check the presence of expected cache tags.
$this->assertCacheTag('config:field.field.node.article.comment');
$this->assertCacheTag('config:user.settings');
$anonymous_comment2 = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName());
......@@ -78,7 +79,7 @@ function testAnonymous() {
// Require contact info.
$this->drupalLogin($this->adminUser);
$this->setCommentAnonymous('2');
$this->setCommentAnonymous(COMMENT_ANONYMOUS_MUST_CONTACT);
$this->drupalLogout();
// Try to post comment with contact info (required).
......
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