Active
Project:
Drupal core
Version:
main
Component:
typed data system
Priority:
Major
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
8 Jan 2014 at 21:23 UTC
Updated:
31 Oct 2025 at 21:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
berdirAnd how should that work exactly?
Definitions can vary by bundle, so which one do we prefer?
Comment #2
fubhy commentedI just ran across this problem while working on the GraphQL module trying to generate the Schema for entities and their bundles. Multiple bundles would make that REALLY awkward. I have no clue how that could possibly work.
Comment #7
wim leersNot only GraphQL is affected, also JSON API. Without this,
EntityDataDefinitionis basically useless.Comment #8
berdirI still don't quite understand what exactly this is trying to achieve. As I said, the same field can for example have a different label or different field settings for different bundles. What would you want to display then? What is this needed for?
Comment #9
gabesullice@Berdir, speaking for the JSON API module: we operate on all fields (updating and normalizing) using the TypedData API. Generally, this would let us deal with both entities and fields more uniformly.
Specifically, this issue was brought back up because we would like to use DataDefinitionInterface::isInternal() for limiting access to "internal" entities rather than multiple implementations of module-specific hooks.
WRT bundle-specific fields,
Drupal\Core\Entity\Plugin\DataType\Deriver\EntityDeriverderives types by bundle, with a data type like:entity:node:article.Comment #10
berdirI see, but afaik having isInternal() support on the entity-type level has nothing to do with this issue. As far as I understand, this is about having a single definition somehow for configurable fields across multiple bundle, but as I said, I don't really see how that would work or why it is major.
I'd suggest to open a separate issue for the isInternal() thing.
Comment #11
wim leersSee #2932035-17: ResourceTypes should be internal when EntityType::isInternal is TRUE by @gabesullice.
Comment #12
wim leersI guess it's not clear what this issue is about exactly. So let's fix that.
Comment #13
gabesulliceUpdated the IS and issue title.
Comment #14
berdirI still don't think that's the same issue and a separate new issue would make more sense to me.
Comment #15
gabesulliceFair enough, reverted IS and title.
New issue: #2936725: EntityDataDefinition::create() does not respect derived entity definitions
Comment #25
wim leersThe same problem occurs for entity types with zero bundles, such as
User.Using a
Node'suidfield's field definition, to then get theentityproperty definition, results in none of the configurable fields on theUserto be found. That's because theentity's::getTargetDefinition()returns(i.e. no bundles set, which is correct)
Which then is the other way of triggering the same bug previously reported here:
\Drupal\Core\Entity\TypedData\EntityDataDefinition::getPropertyDefinitions()does:which hits the
else-branch because$bundles === NULL, and hence it explicitly calls::getBaseFieldDefinitions(). 😭Comment #26
wim leersFix: https://git.drupalcode.org/project/canvas/-/merge_requests/242/diffs?com...
Comment #27
berdirIf a an entity type has no bundles then the bundle is the entity type. For user, that is user. That means ->getFieldDefinitions('user', 'user')
See \Drupal\Core\Entity\EntityTypeBundleInfo::getAllBundleInfo() and \Drupal\Core\Entity\ContentEntityBase::__construct().
You can also see this in \Drupal\Core\Entity\Plugin\DataType\EntityAdapter::createFromEntity(). bundle is always set.
I'm not sure where EntityDataDefinition::create('user') is called as opposed to EntityDataDefinition::create('user', 'user').
We could add a special case to fall back to that but I think it's up to the caller to set the bundle in this case, same as EntityAdapter.
I can only repeat what I've been doing for 10 years, multiple bundles and no bundle (which isn't really a thing as there is always one bundle) is very different and shouldn't be mixed up in the same issue.