TaxonomyTranslationTestTrait.php in Zircon Profile 8.0
File
core/modules/taxonomy/src/Tests/TaxonomyTranslationTestTrait.php
View source
<?php
namespace Drupal\taxonomy\Tests;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
trait TaxonomyTranslationTestTrait {
use EntityReferenceTestTrait;
protected $vocabulary;
protected $termFieldName = 'field_tag';
protected $baseLangcode = 'en';
protected $translateToLangcode = 'hu';
protected $node;
protected function setupLanguages() {
ConfigurableLanguage::createFromLangcode($this->translateToLangcode)
->save();
$this
->rebuildContainer();
}
protected function enableTranslation() {
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
\Drupal::service('content_translation.manager')
->setEnabled('taxonomy_term', $this->vocabulary
->id(), TRUE);
drupal_static_reset();
\Drupal::entityManager()
->clearCachedDefinitions();
\Drupal::service('router.builder')
->rebuild();
\Drupal::service('entity.definition_update_manager')
->applyUpdates();
}
protected function setUpTermReferenceField() {
$handler_settings = array(
'target_bundles' => array(
$this->vocabulary
->id() => $this->vocabulary
->id(),
),
'auto_create' => TRUE,
);
$this
->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName);
$field_storage
->setTranslatable(FALSE);
$field_storage
->save();
entity_get_form_display('node', 'article', 'default')
->setComponent($this->termFieldName, array(
'type' => 'entity_reference_autocomplete_tags',
))
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->termFieldName, array(
'type' => 'entity_reference_label',
))
->save();
}
}