Mercurial > hg > isophonics-drupal-site
comparison core/modules/taxonomy/src/Tests/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\taxonomy\Tests; | |
4 | |
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); | |
6 | |
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; | |
11 | |
12 /** | |
13 * Provides common testing base for translated taxonomy terms. | |
14 * | |
15 * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. | |
16 * Use \Drupal\Tests\taxonomy\Functional\TaxonomyTranslationTestTrait | |
17 */ | |
18 trait TaxonomyTranslationTestTrait { | |
19 | |
20 use EntityReferenceTestTrait; | |
21 | |
22 /** | |
23 * The vocabulary. | |
24 * | |
25 * @var \Drupal\taxonomy\Entity\Vocabulary; | |
26 */ | |
27 protected $vocabulary; | |
28 | |
29 /** | |
30 * The field name for our taxonomy term field. | |
31 * | |
32 * @var string | |
33 */ | |
34 protected $termFieldName = 'field_tag'; | |
35 | |
36 /** | |
37 * The langcode of the source language. | |
38 * | |
39 * @var string | |
40 */ | |
41 protected $baseLangcode = 'en'; | |
42 | |
43 /** | |
44 * Target langcode for translation. | |
45 * | |
46 * @var string | |
47 */ | |
48 protected $translateToLangcode = 'hu'; | |
49 | |
50 /** | |
51 * The node to check the translated value on. | |
52 * | |
53 * @var \Drupal\node\Entity\Node | |
54 */ | |
55 protected $node; | |
56 | |
57 /** | |
58 * Adds additional languages. | |
59 */ | |
60 protected function setupLanguages() { | |
61 ConfigurableLanguage::createFromLangcode($this->translateToLangcode)->save(); | |
62 $this->rebuildContainer(); | |
63 } | |
64 | |
65 /** | |
66 * Enables translations where it needed. | |
67 */ | |
68 protected function enableTranslation() { | |
69 // Enable translation for the current entity type and ensure the change is | |
70 // picked up. | |
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(); | |
77 } | |
78 | |
79 /** | |
80 * Adds term reference field for the article content type. | |
81 */ | |
82 protected function setUpTermReferenceField() { | |
83 $handler_settings = [ | |
84 'target_bundles' => [ | |
85 $this->vocabulary->id() => $this->vocabulary->id(), | |
86 ], | |
87 'auto_create' => TRUE, | |
88 ]; | |
89 $this->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); | |
90 $field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName); | |
91 $field_storage->setTranslatable(FALSE); | |
92 $field_storage->save(); | |
93 | |
94 entity_get_form_display('node', 'article', 'default') | |
95 ->setComponent($this->termFieldName, [ | |
96 'type' => 'entity_reference_autocomplete_tags', | |
97 ]) | |
98 ->save(); | |
99 entity_get_display('node', 'article', 'default') | |
100 ->setComponent($this->termFieldName, [ | |
101 'type' => 'entity_reference_label', | |
102 ]) | |
103 ->save(); | |
104 } | |
105 | |
106 } |