function Node::getFieldData

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()
  2. 8.9.x core/modules/node/src/Plugin/migrate/source/d6/Node.php \Drupal\node\Plugin\migrate\source\d6\Node::getFieldData()
  3. 10 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 and sorted by delta.

1 call to Node::getFieldData()
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 274

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']);
        // If there are no columns then there are no values to return.
        if (empty($columns)) {
            return [];
        }
        // 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'))
            ->orderBy('delta')
            ->execute()
            ->fetchAllAssoc('delta');
    }
    else {
        return [];
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.