can I call my entity checkCreateAccess function from custom code? I have several custom entities in my projects.

To check access for certain links, I would like to utilize the checkAccess() and checkCreateAccess() functions in the MyEntityAccessControlHandler classes.

How do I call these from the Controller class or from the module file?
Something like this should do the trick.

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;    

$entity_type_mgr = \Drupal::getContainer()-&gt;get('entity_type.manager');
if (!$entity_type_mgr-&gt;getAccessControlHandler($type)-&gt;createAccess($bundle)) {
  $permission = "create $bundle $type entities";
  throw new AccessDeniedHttpException("You don't have permission to " . $permission);
}