Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The node type property is now a string field on the entity. When #1757452: Support config entities in entity reference fields is committed, change this to an entity reference field for easier access to the node type entity.
Comment | File | Size | Author |
---|---|---|---|
#8 | 2039607-8.patch | 3.05 KB | claudiu.cristea |
Comments
Comment #1
claudiu.cristeaSure we want this? Because getting all article nids was (so) straight.
$nids = db_query("SELECT nid FROM {node} WHERE type = :type", array(':type' => 'article'))->fetchCol()
:(Comment #2
tstoecklerIn the new world order, that's what Entity
FieldQuery is for:Something like
should do the trick. In D8 you will almost never write a direct query anyway, unless you're writing a storage backend.
Edit: Apparently, EFQ -> EQ
Comment #3
claudiu.cristeaThis means that
type
will go out from{node}
(plus{node_field_data}
,{node_field_revision}
) and will be stored, as body, in his own table?More:
Comment #4
amateescu CreditAttribution: amateescu commentedI hope what Xano meant was to use the entity reference field that came with the new Entity API (
Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem
) not the configurable field provided by the Entity reference module (Drupal\field\Plugin\Type\FieldType\ConfigEntityReferenceItemBase
), which means that it will still be stored in the base tables of the node entity.Comment #5
XanoYes, that's what I meant. I'm sorry for the confusion. It's easy to mix those two things up.
Comment #6
claudiu.cristeaOk, ok, that sounds good. I was tempted to take this task but I got no other similar example in core and, as I'm not 100% familiar with this, I don't know exactly were to start :)
Comment #7
XanoA similar situation would be the node uid field, which is also an entity reference. Thing is if you make a patch now, it will most certainly break, because #1757452: Support config entities in entity reference fields isn't in yet. You can, however, start working on it, so we have a non-test usage of the patch in that issue.
Comment #8
claudiu.cristeaI think this is what we want here... or I'm missing something.
With this patch, the node type entity can be reached in this way:
Comment #9
amateescu CreditAttribution: amateescu commentedYep, that's exactly what we need :) This probably needs to be extended to all content entity types, and I would prefer to do it in a single issue/patch since it's such a small change.
Comment #10
claudiu.cristeaFrom IRC:
It seems to me a read-only property but let's debate this. Opinions?
Comment #12
claudiu.cristeaUnfortunately it breaks Condition tests. What I found is that validate fails in
\Drupal\Core\Plugin\ContextAwarePluginBase::setContextValue()
. It seems that, somewhere, the validation still tries to check$node->type[0]['target_id']
for node type value. It should check$node->type
.EDIT: And this seems something changed by the fact that
type
is nowentity_reference_field
.Comment #13
claudiu.cristeaThink somebody else has to take this.
Comment #14
klausiComment #15
klausiThis has been committed already in #2112239: Convert base field and property definitions, yay!
Comment #16
xjm