$enity = entity_create('comment', array('nid' => $node->nid)); should be able properly populate $entity->nid->value for better DX and to ease migration.

In order to support the same for text fields, #1778178: Convert comments to the new Entity Field API extended the previous rule of "ok, if there are just one contained value, go with that" to "ok, go with the first value if there is just one value given".

A possible alternative, would be default to 'value' only, what is what efq uses right now. We could also make it configurable by field type, so it's magic but defined.

Next, if we decide to refactor entity creation also, we could maybe even remove that logic. See #1785360: Remove entity_create() wrapper?. Still, it would be nice to have for efq as well.

Note, that his also applies to regular setters, e.g. you can do
$comment->nid = 3;
instead of
$comment->nid->value = 3;

However, I think the later is better as you can read 3 from the same place you've set, so we should go with that. So dropping support for the first one would be fine (or even superior) to me, what means we could move over that logic into entity_create() also.

Comments

Berdir’s picture

Status: Active » Closed (duplicate)

I'm quite sure we can do this, so closing?