-2

System: Drupal 8

Can you point me how to fetch all fields of a node? It is better to use \Drupal::entityQuery('node') or \Drupal::service('entity_type.manager')->getStorage('node')? I tried like this:

With \Drupal::entityQuery('node')

$query = \Drupal::entityQuery('node');
$query->condition('status', 1);
$query->condition('type', 'products_product');
$query->condition('field_product_url', 'aero_cldb');
$entity = $query->execute();
dump($entity);

But the result is only the id 925:

array:1 [▼
  2794 => "925" // dunno what means 2794
]

Where is some doc? What means status flag?

With \Drupal::service('entity_type.manager')->getStorage('node')

This one result a dump:

NodeStorage {#257 ▼
  #tableMapping: DefaultTableMapping {#481 ▶}
  #revisionKey: "vid"
  #langcodeKey: "langcode"
  #defaultLangcodeKey: "default_langcode"
  #baseTable: "node"
  #revisionTable: "node_revision"
  #dataTable: "node_field_data"
  #revisionDataTable: "node_field_revision"
  #database: Connection {#15 ▶}
  #storageSchema: null
  #languageManager: ConfigurableLanguageManager {#208 ▶}
  #temporary: false
  #bundleKey: "type"
  #entityManager: EntityManager {#150 ▶}
  #cacheBackend: DatabaseBackend {#266 ▶}
  #entities: []
  #entityTypeId: "node"
  #entityType: ContentEntityType {#383 ▶}
  #idKey: "nid"
  #uuidKey: "uuid"
  #uuidService: null
  #entityClass: "Drupal\node\Entity\Node"
  #moduleHandler: ModuleHandler {#26 ▶}
  #stringTranslation: TranslationManager {#212 ▶}
  #_serviceIds: []
  #_entityStorages: []
}

Is it right? But what next? And which king of select is better?

All the way, the most important think ho to serialize it into JSON with using https://www.drupal.org/docs/drupal-apis/serialization-api? OK on the other hand I can try to see the doc what I found, but thanx to point me how to fetch the node with its full data and references

2
  • 1
    Where is some doc? Where it is supposed to be, right in front of the function definition
    – Hudri
    Jan 13 at 16:15
  • Thanks for no answer! I had more questions, for example what to prefer, entityQuery or \Drupal::service('entity_type.manager'). Or any other advice? You comment is ridiculous.
    – Maxo
    Jan 14 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.