Mercurial > hg > isophonics-drupal-site
comparison core/modules/taxonomy/tests/src/Functional/TaxonomyTranslationTestTrait.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\taxonomy\Functional; | |
4 | |
5 use Drupal\Core\Field\FieldStorageDefinitionInterface; | |
6 use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; | |
7 use Drupal\field\Entity\FieldStorageConfig; | |
8 use Drupal\language\Entity\ConfigurableLanguage; | |
9 | |
10 /** | |
11 * Provides common testing base for translated taxonomy terms. | |
12 */ | |
13 trait TaxonomyTranslationTestTrait { | |
14 | |
15 use EntityReferenceTestTrait; | |
16 | |
17 /** | |
18 * The vocabulary. | |
19 * | |
20 * @var \Drupal\taxonomy\Entity\Vocabulary; | |
21 */ | |
22 protected $vocabulary; | |
23 | |
24 /** | |
25 * The field name for our taxonomy term field. | |
26 * | |
27 * @var string | |
28 */ | |
29 protected $termFieldName = 'field_tag'; | |
30 | |
31 /** | |
32 * The langcode of the source language. | |
33 * | |
34 * @var string | |
35 */ | |
36 protected $baseLangcode = 'en'; | |
37 | |
38 /** | |
39 * Target langcode for translation. | |
40 * | |
41 * @var string | |
42 */ | |
43 protected $translateToLangcode = 'hu'; | |
44 | |
45 /** | |
46 * The node to check the translated value on. | |
47 * | |
48 * @var \Drupal\node\Entity\Node | |
49 */ | |
50 protected $node; | |
51 | |
52 /** | |
53 * Adds additional languages. | |
54 */ | |
55 protected function setupLanguages() { | |
56 ConfigurableLanguage::createFromLangcode($this->translateToLangcode)->save(); | |
57 $this->rebuildContainer(); | |
58 } | |
59 | |
60 /** | |
61 * Enables translations where it needed. | |
62 */ | |
63 protected function enableTranslation() { | |
64 // Enable translation for the current entity type and ensure the change is | |
65 // picked up. | |
66 \Drupal::service('content_translation.manager')->setEnabled('node', 'article', TRUE); | |
67 \Drupal::service('content_translation.manager')->setEnabled('taxonomy_term', $this->vocabulary->id(), TRUE); | |
68 drupal_static_reset(); | |
69 \Drupal::entityManager()->clearCachedDefinitions(); | |
70 \Drupal::service('router.builder')->rebuild(); | |
71 \Drupal::service('entity.definition_update_manager')->applyUpdates(); | |
72 } | |
73 | |
74 /** | |
75 * Adds term reference field for the article content type. | |
76 */ | |
77 protected function setUpTermReferenceField() { | |
78 $handler_settings = [ | |
79 'target_bundles' => [ | |
80 $this->vocabulary->id() => $this->vocabulary->id(), | |
81 ], | |
82 'auto_create' => TRUE, | |
83 ]; | |
84 $this->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); | |
85 $field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName); | |
86 $field_storage->setTranslatable(FALSE); | |
87 $field_storage->save(); | |
88 | |
89 entity_get_form_display('node', 'article', 'default') | |
90 ->setComponent($this->termFieldName, [ | |
91 'type' => 'entity_reference_autocomplete_tags', | |
92 ]) | |
93 ->save(); | |
94 entity_get_display('node', 'article', 'default') | |
95 ->setComponent($this->termFieldName, [ | |
96 'type' => 'entity_reference_label', | |
97 ]) | |
98 ->save(); | |
99 } | |
100 | |
101 } |