Untitled

mail@pastecode.io avatarunknown
plain_text
2 months ago
855 B
1
Indexable
Never
use Drupal\Core\Database\Database;

/**
 * Fetch nodes of a specific type with field_request_workflow_state_value field using JOIN.
 */
function fetchNodesWithWorkflowStateFieldByType($nodeType) {
  $database = Database::getConnection();
  $query = $database->select('node_field_data', 'nfd')
    ->fields('nfd', ['nid', 'title'])
    ->condition('nfd.type', $nodeType) // Replace $nodeType with your desired node type.
    ->join('node__field_request_workflow_state', 'wf_state', 'nfd.nid = wf_state.entity_id')
    ->fields('wf_state', ['field_request_workflow_state_value']);

  $result = $query->execute();

  $nodes = [];
  foreach ($result as $row) {
    $nodes[] = [
      'nid' => $row->nid,
      'title' => $row->title,
      'workflow_state' => $row->field_request_workflow_state_value,
    ];
  }

  return $nodes;
}