private function CommerceSmartImporerService::renameDuplicateFieldDefinitions in Commerce Smart Importer 8
Renames field definitions if there are more fields with same label.
1 call to CommerceSmartImporerService::renameDuplicateFieldDefinitions()
- CommerceSmartImporerService::getFieldDefinition in src/
Plugin/ CommerceSmartImporerService.php - Formats field definition for given product and variation type.
File
- src/
Plugin/ CommerceSmartImporerService.php, line 1135 - Main Commerce Smart Importer Service.
Class
- CommerceSmartImporerService
- This is main Commerce Smart Importer Service.
Namespace
Drupal\commerce_smart_importer\PluginCode
private function renameDuplicateFieldDefinitions(&$fields) {
$used_labels = [];
$duplicate_labels = [];
foreach ($fields['product'] as $key => $field) {
if (in_array($field['label'], $used_labels)) {
$duplicate_labels[] = $field['label'];
}
else {
$used_labels[] = $field['label'];
}
}
foreach ($fields['variation'] as $key => $field) {
if (in_array($field['label'], $used_labels)) {
$duplicate_labels[] = $field['label'];
}
else {
$used_labels[] = $field['label'];
}
}
foreach ($fields['product'] as $key => $field) {
if (in_array($field['label'], $duplicate_labels)) {
$fields['product'][$key]['label'] .= '(' . $fields['product'][$key]['machine_names'] . ')';
}
}
foreach ($fields['variation'] as $key => $field) {
if (in_array($field['label'], $duplicate_labels)) {
$fields['variation'][$key]['label'] .= '(' . $fields['variation'][$key]['machine_names'] . ')';
}
}
}