function twitter_profile_widget_block_content_view_alter in Twitter Profile Widget 8.2
Same name and namespace in other branches
- 8 twitter_profile_widget.module \twitter_profile_widget_block_content_view_alter()
- 3.x twitter_profile_widget.module \twitter_profile_widget_block_content_view_alter()
Implements hook_ENTITY_TYPE_view_alter().
File
- ./
twitter_profile_widget.module, line 57 - Contains twitter_profile_widget.module.
Code
function twitter_profile_widget_block_content_view_alter(array &$build, BlockContentInterface $entity, EntityViewDisplayInterface $display) {
// Add the 'max age' cache for render cache of twitter widget blocks.
if ($entity
->bundle() == 'twitter_widget') {
$max_age = \Drupal::config('twitter_profile_widget.settings')
->get('twitter_widget_cache_time');
$cache_permanent = empty($build['#cache']['max-age']) || $build['#cache']['max-age'] === Cache::PERMANENT;
if ($cache_permanent || $max_age < $build['#cache']['max-age']) {
$build['#cache']['max-age'] = $max_age;
$build['#cache']['tags'][] = 'twitter_profile_widget';
}
}
}