function FieldableEntity::getFieldValues
Same name in other branches
- 9 core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity::getFieldValues()
- 8.9.x core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity::getFieldValues()
- 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.
Typically, getFieldValues() is used in the prepareRow method of a source plugin where the return values are placed on the row source.
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 and sorted by delta.
8 calls to FieldableEntity::getFieldValues()
- Comment::prepareRow in core/
modules/ comment/ src/ Plugin/ migrate/ source/ d7/ Comment.php - CommentEntityTranslation::prepareRow in core/
modules/ comment/ src/ Plugin/ migrate/ source/ d7/ CommentEntityTranslation.php - Node::prepareRow in core/
modules/ node/ src/ Plugin/ migrate/ source/ d7/ Node.php - NodeEntityTranslation::prepareRow in core/
modules/ node/ src/ Plugin/ migrate/ source/ d7/ NodeEntityTranslation.php - Term::prepareRow in core/
modules/ taxonomy/ src/ Plugin/ migrate/ source/ d7/ Term.php
File
-
core/
modules/ migrate_drupal/ src/ Plugin/ migrate/ source/ d7/ FieldableEntity.php, line 87
Class
- FieldableEntity
- Base class for D7 source plugins which need to collect field values.
Namespace
Drupal\migrate_drupal\Plugin\migrate\source\d7Code
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)
->orderBy('delta');
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 (str_starts_with($key, $field)) {
$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.