Score:0

How do I get the values of multiple fields?

us flag

I'm using Drupal 9 and created a module for a custom schema.

Is there a way to simply get all the values for entity fields?
Is it efficient to access each value one by one?

cn flag
It depends exactly what you need, but `$node->toArray()` is probably the simplest. Assuming you mean efficiency in terms of clock cycles, I wouldn't worry about it too much at this level. Whatever method you use to get the values will be going through the same API, so it's negligible. For example, using the method in your question (line by line) will be slightly quicker than `toArray()` as you don't have the overhead of discovering and looping over the fields. But it's less readable and maintainable, and unless it's causing you a specific slowdown, probably a sacrifice worth making
apaderno avatar
us flag
Seeing the code that is using the field values would help to give a better answer. Otherwise, @Clive's comment summarizes perfectly the situation.
SlowCheetah avatar
us flag
Thank you guys. I'll use the general methods you mentioned.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.