X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fmigrate_drupal%2Fsrc%2FPlugin%2Fmigrate%2Fsource%2Fd7%2FFieldableEntity.php;fp=web%2Fcore%2Fmodules%2Fmigrate_drupal%2Fsrc%2FPlugin%2Fmigrate%2Fsource%2Fd7%2FFieldableEntity.php;h=fe0fe486fb2b289458103973ff19b7ad7dfd3d46;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=95275139cc2c93e4e9ca9c841b3d24524d103e3b;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/web/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php b/web/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php index 95275139c..fe0fe486f 100644 --- a/web/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php +++ b/web/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php @@ -22,13 +22,18 @@ abstract class FieldableEntity extends DrupalSqlBase { * The field instances, keyed by field name. */ protected function getFields($entity_type, $bundle = NULL) { - return $this->select('field_config_instance', 'fci') + $query = $this->select('field_config_instance', 'fci') ->fields('fci') - ->condition('entity_type', $entity_type) - ->condition('bundle', isset($bundle) ? $bundle : $entity_type) - ->condition('deleted', 0) - ->execute() - ->fetchAllAssoc('field_name'); + ->condition('fci.entity_type', $entity_type) + ->condition('fci.bundle', isset($bundle) ? $bundle : $entity_type) + ->condition('fci.deleted', 0); + + // Join the 'field_config' table and add the 'translatable' setting to the + // query. + $query->leftJoin('field_config', 'fc', 'fci.field_id = fc.id'); + $query->addField('fc', 'translatable'); + + return $query->execute()->fetchAllAssoc('field_name'); } /** @@ -42,13 +47,13 @@ abstract class FieldableEntity extends DrupalSqlBase { * The entity ID. * @param int|null $revision_id * (optional) The entity revision ID. + * @param string $language + * (optional) The field language. * * @return array * The raw field values, keyed by delta. - * - * @todo Support multilingual field values. */ - protected function getFieldValues($entity_type, $field, $entity_id, $revision_id = NULL) { + 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') @@ -58,6 +63,11 @@ abstract class FieldableEntity extends DrupalSqlBase { 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) { @@ -71,4 +81,44 @@ abstract class FieldableEntity extends DrupalSqlBase { return $values; } + /** + * Checks if an entity type uses Entity Translation. + * + * @param string $entity_type + * The entity type. + * + * @return bool + * Whether the entity type uses entity translation. + */ + protected function isEntityTranslatable($entity_type) { + return in_array($entity_type, $this->variableGet('entity_translation_entity_types', []), TRUE); + } + + /** + * Gets an entity source language from the 'entity_translation' table. + * + * @param string $entity_type + * The entity type. + * @param int $entity_id + * The entity ID. + * + * @return string|bool + * The entity source language or FALSE if no source language was found. + */ + protected function getEntityTranslationSourceLanguage($entity_type, $entity_id) { + try { + return $this->select('entity_translation', 'et') + ->fields('et', ['language']) + ->condition('entity_type', $entity_type) + ->condition('entity_id', $entity_id) + ->condition('source', '') + ->execute() + ->fetchField(); + } + // The table might not exist. + catch (\Exception $e) { + return FALSE; + } + } + }