Commit 7f68a3d4 authored by catch's avatar catch

Issue #2941058 by bn_code, chiranjeeb2410, plach, Gábor Hojtsy, Berdir: Switch...

Issue #2941058 by bn_code, chiranjeeb2410, plach, Gábor Hojtsy, Berdir: Switch from "column" to "property" terminology in the field translation synchronizer
parent b89d3e4f
......@@ -202,7 +202,7 @@ protected function getOriginalEntity(ContentEntityInterface $entity) {
/**
* {@inheritdoc}
*/
public function synchronizeItems(array &$values, array $unchanged_items, $sync_langcode, array $translations, array $columns) {
public function synchronizeItems(array &$values, array $unchanged_items, $sync_langcode, array $translations, array $properties) {
$source_items = $values[$sync_langcode];
// Make sure we can detect any change in the source items.
......@@ -218,7 +218,7 @@ public function synchronizeItems(array &$values, array $unchanged_items, $sync_l
// for each column.
for ($delta = 0; $delta < $total; $delta++) {
foreach (['old' => $unchanged_items, 'new' => $source_items] as $key => $items) {
if ($item_id = $this->itemHash($items, $delta, $columns)) {
if ($item_id = $this->itemHash($items, $delta, $properties)) {
$change_map[$item_id][$key][] = $delta;
}
}
......@@ -251,7 +251,7 @@ public function synchronizeItems(array &$values, array $unchanged_items, $sync_l
$old_delta = NULL;
$new_delta = NULL;
if ($item_id = $this->itemHash($source_items, $delta, $columns)) {
if ($item_id = $this->itemHash($source_items, $delta, $properties)) {
if (!empty($change_map[$item_id]['old'])) {
$old_delta = array_shift($change_map[$item_id]['old']);
}
......@@ -272,7 +272,7 @@ public function synchronizeItems(array &$values, array $unchanged_items, $sync_l
// items and the other columns from the existing values. This only
// works if the delta exists in the language.
elseif ($created && !empty($original_field_values[$langcode][$delta])) {
$values[$langcode][$delta] = $this->createMergedItem($source_items[$delta], $original_field_values[$langcode][$delta], $columns);
$values[$langcode][$delta] = $this->createMergedItem($source_items[$delta], $original_field_values[$langcode][$delta], $properties);
}
// If the delta doesn't exist, copy from the source language.
elseif ($created) {
......@@ -290,7 +290,7 @@ public function synchronizeItems(array &$values, array $unchanged_items, $sync_l
// we may have desynchronized field values, so we make sure that
// untranslatable properties are synchronized, even if in any other
// situation this would not be necessary.
$values[$langcode][$new_delta] = $this->createMergedItem($source_items[$new_delta], $item, $columns);
$values[$langcode][$new_delta] = $this->createMergedItem($source_items[$new_delta], $item, $properties);
}
}
}
......@@ -324,19 +324,19 @@ protected function createMergedItem(array $source_item, array $target_item, arra
* An array of field items.
* @param int $delta
* The delta identifying the item to be processed.
* @param array $columns
* @param array $properties
* An array of column names to be synchronized.
*
* @returns string
* A hash code that can be used to identify the item.
*/
protected function itemHash(array $items, $delta, array $columns) {
protected function itemHash(array $items, $delta, array $properties) {
$values = [];
if (isset($items[$delta])) {
foreach ($columns as $column) {
if (!empty($items[$delta][$column])) {
$value = $items[$delta][$column];
foreach ($properties as $property) {
if (!empty($items[$delta][$property])) {
$value = $items[$delta][$property];
// String and integer values are by far the most common item values,
// thus we special-case them to improve performance.
$values[] = is_string($value) || is_int($value) ? $value : hash('sha256', serialize($value));
......
......@@ -50,10 +50,10 @@ public function synchronizeFields(ContentEntityInterface $entity, $sync_langcode
* The language code of the items to use as source values.
* @param array $translations
* An array of all the available language codes for the given field.
* @param array $columns
* An array of column names to be synchronized.
* @param array $properties
* An array of property names to be synchronized.
*/
public function synchronizeItems(array &$field_values, array $unchanged_items, $sync_langcode, array $translations, array $columns);
public function synchronizeItems(array &$field_values, array $unchanged_items, $sync_langcode, array $translations, array $properties);
/**
* Returns the synchronized properties for the specified field definition.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment