Skip to content
Snippets Groups Projects
Commit e1773d77 authored by Youri van Koppen's avatar Youri van Koppen Committed by Youri van Koppen
Browse files

Issue #3139441 by MegaChriz: Fixed autocreating terms in the "default"...

Issue #3139441 by MegaChriz: Fixed autocreating terms in the "default" language makes terms not editable in the UI.
parent cb2ecae4
No related branches found
No related tags found
No related merge requests found
......@@ -613,16 +613,17 @@ abstract class EntityProcessorBase extends ProcessorBase implements EntityProces
}
/**
* Returns the current language for entities.
*
* This checks if the configuration value is valid.
*
* @return string
* The current language code.
* {@inheritdoc}
*/
protected function entityLanguage() {
public function entityLanguage() {
$langcodes = $this->languageOptions();
return isset($langcodes[$this->configuration['langcode']]) ? $this->configuration['langcode'] : LanguageInterface::LANGCODE_DEFAULT;
if (isset($this->configuration['langcode']) && isset($langcodes[$this->configuration['langcode']])) {
return $this->configuration['langcode'];
}
// Return default language.
return $this->languageManager->getDefaultLanguage()->getId();
}
/**
......
......@@ -31,4 +31,12 @@ interface EntityProcessorInterface extends ProcessorInterface, ClearableInterfac
*/
public function getEntityTranslation(FeedInterface $feed, TranslatableInterface $entity, $langcode);
/**
* Returns the current language for entities.
*
* @return string
* The current language code.
*/
public function entityLanguage();
}
......@@ -386,7 +386,18 @@ abstract class FieldTargetBase extends TargetBase implements ConfigurableTargetI
* {@inheritdoc}
*/
public function getLangcode() {
return !empty($this->configuration['language']) ? $this->configuration['language'] : LanguageInterface::LANGCODE_DEFAULT;
if (!empty($this->configuration['language'])) {
return $this->configuration['language'];
}
// Get the language from the processor, if the processor has one.
$processor = $this->feedType->getProcessor();
if ($processor instanceof EntityProcessorInterface) {
return $processor->entityLanguage();
}
// Return default language.
return $this->getLanguageManager()->getDefaultLanguage()->getId();
}
}
......@@ -164,6 +164,37 @@ class TranslationTest extends FeedsKernelTestBase {
$this->assertEquals('Este es el texto del cuerpo.', $node->field_alpha->value);
}
/**
* Tests that the language setting on the processor is respected.
*
* In this case there's no language configured on the targets.
*/
public function testImportInProcessorConfiguredLanguage() {
// Set language to Spanish.
$configuration = $this->feedType->getProcessor()->getConfiguration();
$configuration['langcode'] = 'es';
$this->feedType->getProcessor()->setConfiguration($configuration);
// Set mappings without configuring language.
$this->feedType->setMappings($this->getMappingsInLanguage(NULL));
$this->feedType->save();
// Import content.
$this->importContent($this->resourcesPath() . '/csv/translation/content_es.csv');
$this->assertNodeCount(1);
// Assert that Spanish values were created.
$node = Node::load(1);
$this->assertEquals('es', $node->language()->getId());
$this->assertEquals('HOLA MUNDO', $node->title->value);
$this->assertEquals('Este es el texto del cuerpo.', $node->field_alpha->value);
// Assert that the created term is in the Spanish language.
$term = Term::load(1);
$this->assertEquals('Termino de taxonomía', $term->name->value);
$this->assertEquals('es', $term->langcode->value);
}
/**
* Tests importing values for two languages separately.
*
......@@ -383,6 +414,32 @@ class TranslationTest extends FeedsKernelTestBase {
$this->assertEquals('es', $term->langcode->value);
}
/**
* Tests importing auto-created terms when no language is configured for it.
*/
public function testAutocreatedTermDefaultLanguage() {
$this->feedType->addMapping([
'target' => 'field_tags',
'map' => ['target_id' => 'terms'],
'settings' => [
'reference_by' => 'name',
'language' => NULL,
'autocreate' => 1,
],
]);
$this->feedType->save();
// Import Spanish content.
$this->importContent($this->resourcesPath() . '/csv/translation/content_es.csv');
$this->assertNodeCount(1);
// Assert that the term was created in the default language.
$default_langcode = $this->container->get('language.default')->get()->getId();
$term = Term::load(1);
$this->assertEquals('Termino de taxonomía', $term->name->value);
$this->assertEquals($default_langcode, $term->langcode->value);
}
/**
* Tests if values are cleared out when importing empty values.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment