You are here

protected function Node::getFieldData in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/node/src/Plugin/migrate/source/d6/Node.php \Drupal\node\Plugin\migrate\source\d6\Node::getFieldData()

Retrieves raw field data for a node.

Parameters

array $field: A field and instance definition from getFieldInfo().

\Drupal\migrate\Row $node: The node.

Return value

array The field values, keyed by delta.

2 calls to Node::getFieldData()
Node::getCckData in core/modules/node/src/Plugin/migrate/source/d6/Node.php
Retrieves raw field data for a node.
Node::getFieldValues in core/modules/node/src/Plugin/migrate/source/d6/Node.php
Gets field values for a node.

File

core/modules/node/src/Plugin/migrate/source/d6/Node.php, line 245

Class

Node
Drupal 6 node source from database.

Namespace

Drupal\node\Plugin\migrate\source\d6

Code

protected function getFieldData(array $field, Row $node) {
  $field_table = 'content_' . $field['field_name'];
  $node_table = 'content_type_' . $node
    ->getSourceProperty('type');

  /** @var \Drupal\Core\Database\Schema $db */
  $db = $this
    ->getDatabase()
    ->schema();
  if ($db
    ->tableExists($field_table)) {
    $query = $this
      ->select($field_table, 't');

    // If the delta column does not exist, add it as an expression to
    // normalize the query results.
    if ($db
      ->fieldExists($field_table, 'delta')) {
      $query
        ->addField('t', 'delta');
    }
    else {
      $query
        ->addExpression(0, 'delta');
    }
  }
  elseif ($db
    ->tableExists($node_table)) {
    $query = $this
      ->select($node_table, 't');

    // Every row should have a delta of 0.
    $query
      ->addExpression(0, 'delta');
  }
  if (isset($query)) {
    $columns = array_keys($field['db_columns']);

    // Add every column in the field's schema.
    foreach ($columns as $column) {
      $query
        ->addField('t', $field['field_name'] . '_' . $column, $column);
    }
    return $query
      ->isNotNull($field['field_name'] . '_' . $columns[0])
      ->condition('nid', $node
      ->getSourceProperty('nid'))
      ->condition('vid', $node
      ->getSourceProperty('vid'))
      ->execute()
      ->fetchAllAssoc('delta');
  }
  else {
    return [];
  }
}