diff --git a/src/Plugin/migrate/source/d7/MultifieldItem.php b/src/Plugin/migrate/source/d7/MultifieldItem.php index c3b192d..cb37d53 100644 --- a/src/Plugin/migrate/source/d7/MultifieldItem.php +++ b/src/Plugin/migrate/source/d7/MultifieldItem.php @@ -55,13 +55,18 @@ class MultifieldItem extends FieldableEntity { $row->setSourceProperty('bundle', $bundle); $fields = $this->getSubfields($this->configuration['field_name']); - // Here I found a way to figure out the structure of each sub-field. - // They are of the form parent_field_name + _ + sub_field_name + _ + suffix - // such as target_id or value. There must be an easier way to figure out - // the above but this is what I found. + // Field values are structured as + // parent_field_name + _ + sub_field_name + _ + some_suffix + // By default we check for + // parent_field_name + _ + sub_field_name + _ + value and if that is + // empty, then we use the first index, which usually returns the + // value such as for target_id in entity reference fields. foreach ($fields as $field_name => $field_config) { - $field_value_suffix = key($field_config['data']['indexes']); - $field_value = $row->getSourceProperty($this->configuration['field_name'] . '_' . $field_name . '_' . $field_value_suffix); + $field_value = $row->getSourceProperty($this->configuration['field_name'] . '_' . $field_name . '_value'); + if (empty($field_value)) { + $field_value_suffix = key($field_config['data']['indexes']); + $field_value = $row->getSourceProperty($this->configuration['field_name'] . '_' . $field_name . '_' . $field_value_suffix); + } $row->setSourceProperty($field_name, $field_value); }