Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#408] Fix team lists cache errors. #419

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,33 @@ public function buildRow(EntityInterface $entity) {
return $row + parent::buildRow($entity);
}

/**
* {@inheritdoc}
*/
public function render() {
arlina-espinoza marked this conversation as resolved.
Show resolved Hide resolved
$build = parent::render();
$account = $this->entityTypeManager->getStorage('user')->load(\Drupal::currentUser()->id());

// Team lists vary for each user.
$build['#cache']['contexts'][] = 'user';

// This team list should be invalidated if the user's permissions change.
$build['#cache']['tags'][] = 'user:' . $account->id();

// This team list should be invalidated if the user roles permissions change.
foreach ($account->getRoles() as $rid) {
arlina-espinoza marked this conversation as resolved.
Show resolved Hide resolved
$build['#cache']['tags'][] = "config:user.role.$rid";
}

// This team list should be invalidated if the team roles permissions change.
$build['#cache']['tags'][] = 'team_role_list';

// Use cache expiration defined in configuration.
$build['#cache']['max-age'] = $this->configFactory
->get('apigee_edge_teams.team_settings')
->get('cache_expiration');

return $build;
}

}