EntityCreateAccessCheck provides a route access checker which can be used in two ways:
For an entity type that does not have bundles, you just give the entity type ID:
requirements:
_entity_create_access: 'menu'
For an entity type that does have bundles, you need to give the entity type ID and a bundle, which can be loaded from a route placeholder:
requirements:
_entity_create_access: 'taxonomy_term:{taxonomy_vocabulary}'
If you use it without the bundle, but with an entity type that does have bundles, nothing breaks, until a contrib modules implements hook_entity_create_access() and expects to find a $bundle parameter, and makes API calls that pass $bundle to APIs that expect it. Then everything breaks and it's really hard to debug. (For example, this problem caused a crash that was apparently in OG, but was caused by the incorrect use of this route access in Commerce -
#2911542: "Add payment" and "Add order" routes need to use _entity_create_any_access, not _entity_create_access β
.)
The use without the bundle value with an entity type that does have bundles is incorrect because:
1. The _entity_create_access router check is handled by EntityCreateAccessCheck, which calls:
return $this->entityManager->getAccessControlHandler($entity_type)->createAccess($bundle, $account, [], TRUE);
2. EntityAccessControlHandlerInterface::createAccess() says:
* @param string $entity_bundle
* (optional) The bundle of the entity. Required if the entity supports
* bundles, defaults to NULL otherwise.
I think EntityCreateAccessCheck should simply throw an exception if the bundle value isn't available for an entity type that has bundles.