When block caching is enabled every page ends up with the same ShareThis links because the default Drupal 7 block caching is DRUPAL_CACHE_PER_ROLE. This module needs DRUPAL_CACHE_PER_PAGE.

I used the following code to fix it on my site, but it should really be changed in the ShareThis module:

/**
 * Implements hook_block_info_alter().
 */
function mymodule_block_info_alter(&$blocks, $theme, $code_blocks) {
  // Change the caching mode for ShareThis blocks to be per page
  if (!empty($blocks['sharethis'])) {
    foreach ($blocks['sharethis'] as $delta => $block) {
      $blocks['sharethis'][$delta]['cache'] = DRUPAL_CACHE_PER_PAGE;
    }
  }
}
CommentFileSizeAuthor
#6 sharethis_block_cache_1586346_6.patch411 bytesGaofengzzz

Comments

ShareThis Support’s picture

Status: Active » Fixed

HI,

Thank you for bringing this to our notice and for providing a solution.
I'll forward it to our dev team.

Regards,
Sharethis Support

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ponies’s picture

Version: 7.x-2.4 » 7.x-2.5
Status: Closed (fixed) » Active

This bug is still active in 2.5. Benshell's code works great. I'll try to roll it into a patch this week.

kublaken’s picture

Doesn't look like this has been patched yet. I had the same problem. ShareThis links were caching and generating the wrong links for users (anon and authenticated). Turning off block caching fixed the problem.

chakrapani’s picture

Thanks benshell. The proposed solution work like charm :)
Surprised that this hasn't been addressed in the module yet. It would be great if someone can add a patch.

Gaofengzzz’s picture

StatusFileSize
new411 bytes

Thanks @benshell, i help create patch for dev version.

dydave’s picture

Status: Active » Needs review

Better set the status to needs review to trigger the Testbot and so that everyone could also work on reviewing the patch.
Watchout for patch file name, standard template could be found at: Making a Drupal patch with Git, in particular, see the details about patch file name:

[project_name]-[short-description]-[issue-number]-[comment-number].patch

Thanks in advance to everyone for the testing/reporting, reviewing and comments.
Cheers!

Gaofengzzz’s picture

Thanks very much @benshell for your patch.

After more than two weeks, with no particular objections or further issues on this ticket, I went ahead and got it committed against the 7.x-2.x branch at 281f8b1.

Gaofengzzz’s picture

Issue summary: View changes

Sorry, forget to change stauts

Gaofengzzz’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.