I have an editor role which can create nodes of all content types. On a specific condition, I want to return access denied on /node/add/specific-content-type. So I did this:
/**  * Implements hook_entity_type_alter().  */ function mymodule_entity_type_alter(array &$entity_types) {   if ($entity_types['node'] instanceof EntityTypeInterface) {     $entity_types['node']->setHandlerClass('access', MyNodeAccessControlHandler::class);   } } 
and then in the createAccess method of the MyNodeAccessControlHandler
public function createAccess($entity_bundle = NULL, AccountInterface $account = NULL, array $context = [], $return_as_object = FALSE) {     if ($condition) {       $result = AccessResult::forbidden('a reason');        return $return_as_object ? $result : $result->isAllowed();     }      return parent::createAccess($entity_bundle, $account, $context, $return_as_object);   }  
This works fine. But now the editor also cannot access the page /node/add. Which should be accessible to the editor and on that page, the editor should not see the specific-content-type in the list.
I am using D9.3