You are here

function get_node_id in Content Import 8.9

To get node available.

1 call to get_node_id()
import_node in ./contentimport.module
To import data as Content type nodes.

File

./contentimport.module, line 113
Module file for Contentimport.

Code

function get_node_id($title) {
  $nodeReference = [];
  $db = \Drupal::database();
  foreach ($title as $key => $value) {
    $query = $db
      ->select('node_field_data', 'n');
    $query
      ->fields('n', [
      'nid',
    ]);
    $nodeId = $query
      ->condition('n.title', trim($value))
      ->execute()
      ->fetchField();
    $nodeReference[$key]['target_id'] = $nodeId;
  }
  return $nodeReference;
}