Problem/Motivation
Since https://www.drupal.org/node/1902034, config entities can be queried using the EntityFieldQuery
API.
However, it appears to be a leaky abstraction, see for example #2934730: Server error when accessing non-fieldable entity resources with filters and #2959445: Entity querying config entities does not work, so neither does JSON API collection filtering: provide helpful DX. The former needed special casing for generating queries for config entities versus content entities. The latter is about not being able to perform a query across storages. Yes, this makes sense. But … it does result in a \Drupal\Core\Entity\Query\Sql\Tables::addField()
call nonetheless, which then fails in \Drupal\Core\Entity\EntityFieldManager::buildBaseFieldDefinitions()
, which throws this exception:
// Fail with an exception for non-fieldable entity types.
if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) {
throw new \LogicException("Getting the base fields is not supported for entity type {$entity_type->getLabel()}.");
}
Proposed resolution
Improve error handling: Detect queries across storages and:
- generate an exception like:
throw new \LogicException("Impossible to query both the %s and %s entity types in a single query, since they are stored separately.");
- And preferably, add a custom exception class for this in
\Drupal\Core\Entity\Exception
, there are already half a dozen there. PerhapsCrossStorageQueryException extends LogicException
?
Remaining tasks
TBD
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
None.
Comments
Comment #2
Wim LeersComment #3
Wim LeersComment #4
bn_code CreditAttribution: bn_code at EPAM Systems commentedComment #5
linichalexey CreditAttribution: linichalexey at EPAM Systems commented