function FieldableEntity::getFieldValues

Same name in other branches
  1. 9 core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity::getFieldValues()
  2. 10 core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity::getFieldValues()
  3. 11.x core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity::getFieldValues()

Retrieves field values for a single field of a single entity.

Parameters

string $entity_type: The entity type.

string $field: The field name.

int $entity_id: The entity ID.

int|null $revision_id: (optional) The entity revision ID.

string $language: (optional) The field language.

Return value

array The raw field values, keyed by delta.

8 calls to FieldableEntity::getFieldValues()
Comment::prepareRow in core/modules/comment/src/Plugin/migrate/source/d7/Comment.php
Adds additional data to the row.
CommentEntityTranslation::prepareRow in core/modules/comment/src/Plugin/migrate/source/d7/CommentEntityTranslation.php
Adds additional data to the row.
Node::prepareRow in core/modules/node/src/Plugin/migrate/source/d7/Node.php
Adds additional data to the row.
NodeEntityTranslation::prepareRow in core/modules/node/src/Plugin/migrate/source/d7/NodeEntityTranslation.php
Adds additional data to the row.
Term::prepareRow in core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php
Adds additional data to the row.

... See full list

File

core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php, line 56

Class

FieldableEntity
Base class for D7 source plugins which need to collect field values from the Field API.

Namespace

Drupal\migrate_drupal\Plugin\migrate\source\d7

Code

protected function getFieldValues($entity_type, $field, $entity_id, $revision_id = NULL, $language = NULL) {
    $table = (isset($revision_id) ? 'field_revision_' : 'field_data_') . $field;
    $query = $this->select($table, 't')
        ->fields('t')
        ->condition('entity_type', $entity_type)
        ->condition('entity_id', $entity_id)
        ->condition('deleted', 0);
    if (isset($revision_id)) {
        $query->condition('revision_id', $revision_id);
    }
    // Add 'language' as a query condition if it has been defined by Entity
    // Translation.
    if ($language) {
        $query->condition('language', $language);
    }
    $values = [];
    foreach ($query->execute() as $row) {
        foreach ($row as $key => $value) {
            $delta = $row['delta'];
            if (strpos($key, $field) === 0) {
                $column = substr($key, strlen($field) + 1);
                $values[$delta][$column] = $value;
            }
        }
    }
    return $values;
}

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