Trying to get the property definitions of a config entity type currently fails with a fatal error:

\Drupal::typedDataManager()->createDataDefinition('entity:node_type')->getPropertyDefinitions();

Fatal error: Call to undefined method Drupal\node\Entity\NodeType::baseFieldDefinitions() in …/core/lib/Drupal/Core/Entity/EntityManager.php on line 348

It is probably planned to add support for config entity types at some point, too. For now, though, it would be nice to at least not let it fail with a fatal error.

Comments

drunken monkey’s picture

Status: Active » Needs review
StatusFileSize
new1.28 KB

Patch attached, though I don't know if that's the right spot to add the check. Maybe this should happen, and be documented, at an earlier stage?

Status: Needs review » Needs work
drunken monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new1.28 KB

One backslash that makes all the difference …

amateescu’s picture

I agree that we should throw an exception for this, but I think that needs to happen a lot sooner.

amateescu’s picture

StatusFileSize
new2.26 KB

Now with patch :)

Status: Needs review » Needs work

The last submitted patch, 5: 2228721-5.patch, failed testing.

amateescu’s picture

Status: Needs work » Needs review

5: 2228721-5.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 5: 2228721-5.patch, failed testing.

The last submitted patch, 4: 2228721-4.patch, failed testing.

The last submitted patch, 4: 2228721-4-test-only.patch, failed testing.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new2.45 KB
new1.79 KB

Discussed a bit in IRC, we need to be able to create those definition objects, we just need to make sure they can't/don't return any property definitions because they don't have any. Another solution would be return an empty array instead of throwing an exception.. me and @Berdir couldn't figure out what would be the best way.

Status: Needs review » Needs work

The last submitted patch, 11: 2228721-11.patch, failed testing.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new4.02 KB
new4.84 KB

More discussions in IRC, @fago prefers to return an empty array when trying to get the property definitions of a config entity *and* throw an exception in EntityManager.

fago’s picture

Yep, the EM method says it supports only content entities - so throwing an exception is totally fine there. However, EntityDataDefinition is for all kind of entities and an exception is not expected/defined by the interface. So the valid question of what kind of properties a config entity has should not thrown an exception. Of course integrating with config schema would be better, but this denotes the status quo.

Patch looks good to me.

berdir’s picture

Shouldn't we be checking for not content entity instead of is config entity, for example calling it with menu_link would still result in a fatal error...

amateescu’s picture

StatusFileSize
new4.01 KB
new1.01 KB

The problem with checking for content entity is that there might be other entity types which don't extend ContentEntityInterface but use the typed data / field definitions system. How about this instead?

berdir’s picture

That will break with #2002138: Use an adapter for supporting typed data on ContentEntities.

We are checking ContentEntityInterface in a number of places, I'm not sure if you can get around not implementing that anymore...

amateescu’s picture

StatusFileSize
new4.01 KB
new773 bytes

I see. So any other entity type which wants to use the typed data system will have be a content entity, but it can still use a different storage handler. Ok then, color me convinced :)

The last submitted patch, 16: 2228721-16.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 18: 2228721-18.patch, failed testing.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new4.82 KB
new835 bytes

Pesky unit tests :)

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Thanks.

  • Commit 2867e69 on 8.x by webchick:
    Issue #2228721 by amateescu, drunken monkey: TypedData doesn't support...
webchick’s picture

Title: TypedData doesn't support config entity types » TypedData doesn't support config entity types; flag errors if you try
Status: Reviewed & tested by the community » Fixed

Hm. Unfortunate that we need to special-case here, but in talking to Tim, this is based on design decisions that were made back in the day. This patch only makes it explicit so people don't get fatal errors.

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.