Skip to content
Snippets Groups Projects
Commit 2c1feffa authored by nico.b's avatar nico.b Committed by Kevin Robinson
Browse files

Issue #3326524: Content of drupalSettings.bestreply not up-to-date

parent a30ca46d
No related branches found
No related tags found
1 merge request!3Issue #3326524: Content of drupalSettings.bestreply not up-to-date
......@@ -52,6 +52,12 @@ function bestreply_node_view(array &$build, EntityInterface $entity, EntityViewD
$build['#attached']['drupalSettings']['bestreply']['name'] = $br_name;
$build['#attached']['drupalSettings']['bestreply']['ismarked'] = $br_id;
// Add cache tags that can be invalidated if best reply is marked or cleared such that
// drupalSettings are always up-to-date.
$build['#cache'] = [
'tags' => ['bestreply:node:' . $entity->id()]
];
if ($if_comments_available && $br_id && \Drupal::currentUser()->hasPermission('view bestreply')) {
$bestreply_comment_link = t('View @bestreply.', ['@bestreply' => $br_name]);
$links['bestreply-view'] = [
......
......@@ -3,6 +3,7 @@
namespace Drupal\bestreply\Controller;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Controller\ControllerBase;
use Drupal\comment\CommentInterface;
......@@ -141,6 +142,9 @@ class BestReplyController extends ControllerBase implements ContainerInjectionIn
'dt' => $dt,
]);
}
Cache::invalidateTags(['bestreply:node:' . $comment->getCommentedEntityId()]);
if ($js) {
$status = ($rt) ? TRUE : FALSE;
print Json::encode([
......@@ -159,6 +163,7 @@ class BestReplyController extends ControllerBase implements ContainerInjectionIn
public function clear(CommentInterface $comment, $js = NULL) {
if (bestreply_ismarked($comment->getCommentedEntityId())) {
$rt = $this->connection->query("DELETE FROM {bestreply} WHERE nid = :nid", ['nid' => $comment->getCommentedEntityId()]);
Cache::invalidateTags(['bestreply:node:' . $comment->getCommentedEntityId()]);
}
if ($js) {
$status = ($rt) ? TRUE : FALSE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment