3 namespace Drupal\taxonomy\Tests;
5 @trigger_error(__NAMESPACE__ . '\TaxonomyTranslationTestTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\taxonomy\Functional\TaxonomyTranslationTestTrait', E_USER_DEPRECATED);
7 use Drupal\Core\Field\FieldStorageDefinitionInterface;
8 use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
9 use Drupal\field\Entity\FieldStorageConfig;
10 use Drupal\language\Entity\ConfigurableLanguage;
13 * Provides common testing base for translated taxonomy terms.
15 * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
16 * Use \Drupal\Tests\taxonomy\Functional\TaxonomyTranslationTestTrait
18 trait TaxonomyTranslationTestTrait {
20 use EntityReferenceTestTrait;
25 * @var \Drupal\taxonomy\Entity\Vocabulary;
27 protected $vocabulary;
30 * The field name for our taxonomy term field.
34 protected $termFieldName = 'field_tag';
37 * The langcode of the source language.
41 protected $baseLangcode = 'en';
44 * Target langcode for translation.
48 protected $translateToLangcode = 'hu';
51 * The node to check the translated value on.
53 * @var \Drupal\node\Entity\Node
58 * Adds additional languages.
60 protected function setupLanguages() {
61 ConfigurableLanguage::createFromLangcode($this->translateToLangcode)->save();
62 $this->rebuildContainer();
66 * Enables translations where it needed.
68 protected function enableTranslation() {
69 // Enable translation for the current entity type and ensure the change is
71 \Drupal::service('content_translation.manager')->setEnabled('node', 'article', TRUE);
72 \Drupal::service('content_translation.manager')->setEnabled('taxonomy_term', $this->vocabulary->id(), TRUE);
73 drupal_static_reset();
74 \Drupal::entityManager()->clearCachedDefinitions();
75 \Drupal::service('router.builder')->rebuild();
76 \Drupal::service('entity.definition_update_manager')->applyUpdates();
80 * Adds term reference field for the article content type.
82 * @param bool $translatable
83 * (optional) If TRUE, create a translatable term reference field. Defaults
86 protected function setUpTermReferenceField() {
89 $this->vocabulary->id() => $this->vocabulary->id(),
91 'auto_create' => TRUE,
93 $this->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
94 $field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName);
95 $field_storage->setTranslatable(FALSE);
96 $field_storage->save();
98 entity_get_form_display('node', 'article', 'default')
99 ->setComponent($this->termFieldName, [
100 'type' => 'entity_reference_autocomplete_tags',
103 entity_get_display('node', 'article', 'default')
104 ->setComponent($this->termFieldName, [
105 'type' => 'entity_reference_label',