/**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\Core\Entity\EntityInterface|\Drupal\user\EntityOwnerInterface $entity */
     if ($account->hasPermission('administer comments')) {
         $access = AccessResult::allowed()->cachePerPermissions();
         return $operation != 'view' ? $access : $access->andIf($entity->getCommentedEntity()->access($operation, $account, TRUE));
     }
     switch ($operation) {
         case 'view':
             return AccessResult::allowedIf($account->hasPermission('access comments') && $entity->isPublished())->cachePerPermissions()->cacheUntilEntityChanges($entity)->andIf($entity->getCommentedEntity()->access($operation, $account, TRUE));
         case 'update':
             return AccessResult::allowedIf($account->id() && $account->id() == $entity->getOwnerId() && $entity->isPublished() && $account->hasPermission('edit own comments'))->cachePerPermissions()->cachePerUser()->cacheUntilEntityChanges($entity);
         default:
             // No opinion.
             return AccessResult::neutral()->cachePerPermissions();
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\Core\Entity\EntityInterface|\Drupal\user\EntityOwnerInterface $entity */
     switch ($operation) {
         case 'view':
             if ($account->hasPermission('access comments') && $entity->isPublished() || $account->hasPermission('administer comments')) {
                 return $entity->getCommentedEntity()->access($operation, $account);
             }
             break;
         case 'update':
             return $account->id() && $account->id() == $entity->getOwnerId() && $entity->isPublished() && $account->hasPermission('edit own comments') || $account->hasPermission('administer comments');
             break;
         case 'delete':
             return $account->hasPermission('administer comments');
             break;
         case 'approve':
             return $account->hasPermission('administer comments');
             break;
     }
 }