comparison core/modules/content_translation/src/ContentTranslationManager.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\content_translation; 3 namespace Drupal\content_translation;
4 4
5 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
5 use Drupal\Core\Entity\EntityInterface; 6 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\workflows\Entity\Workflow; 7 use Drupal\workflows\Entity\Workflow;
8 use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
9 use Drupal\Core\Entity\EntityTypeManagerInterface;
8 10
9 /** 11 /**
10 * Provides common functionality for content translation. 12 * Provides common functionality for content translation.
11 */ 13 */
12 class ContentTranslationManager implements ContentTranslationManagerInterface, BundleTranslationSettingsInterface { 14 class ContentTranslationManager implements ContentTranslationManagerInterface, BundleTranslationSettingsInterface {
15 use DeprecatedServicePropertyTrait;
16
17 /**
18 * {@inheritdoc}
19 */
20 protected $deprecatedProperties = [
21 'entityManager' => 'entity.manager',
22 'updatesManager' => 'content_translation.updates_manager',
23 ];
24
25 /**
26 * The entity type bundle info provider.
27 *
28 * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
29 */
30 protected $entityTypeBundleInfo;
13 31
14 /** 32 /**
15 * The entity type manager. 33 * The entity type manager.
16 * 34 *
17 * @var \Drupal\Core\Entity\EntityManagerInterface 35 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
18 */ 36 */
19 protected $entityManager; 37 protected $entityTypeManager;
20
21 /**
22 * The updates manager.
23 *
24 * @var \Drupal\content_translation\ContentTranslationUpdatesManager
25 */
26 protected $updatesManager;
27 38
28 /** 39 /**
29 * Constructs a ContentTranslationManageAccessCheck object. 40 * Constructs a ContentTranslationManageAccessCheck object.
30 * 41 *
31 * @param \Drupal\Core\Entity\EntityManagerInterface $manager 42 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
32 * The entity type manager. 43 * The entity type manager.
33 * @param \Drupal\content_translation\ContentTranslationUpdatesManager $updates_manager 44 * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
34 * The updates manager. 45 * The entity type bundle info provider.
35 */ 46 */
36 public function __construct(EntityManagerInterface $manager, ContentTranslationUpdatesManager $updates_manager) { 47 public function __construct(EntityTypeManagerInterface $entity_type_manager, $entity_type_bundle_info) {
37 $this->entityManager = $manager; 48 $this->entityTypeManager = $entity_type_manager;
38 $this->updatesManager = $updates_manager; 49
50 if (!($entity_type_bundle_info instanceof EntityTypeBundleInfoInterface)) {
51 @trigger_error('The entity_type.bundle.info service should be passed to ContentTranslationManager::__construct() instead of the content_translation.updates_manager service since 8.7.0. This will be required in Drupal 9.0.0. See https://www.drupal.org/node/2549139 and https://www.drupal.org/node/2973222.', E_USER_DEPRECATED);
52 $entity_type_bundle_info = \Drupal::service('entity_type.bundle.info');
53 }
54 $this->entityTypeBundleInfo = $entity_type_bundle_info;
39 } 55 }
40 56
41 /** 57 /**
42 * {@inheritdoc} 58 * {@inheritdoc}
43 */ 59 */
44 public function getTranslationHandler($entity_type_id) { 60 public function getTranslationHandler($entity_type_id) {
45 return $this->entityManager->getHandler($entity_type_id, 'translation'); 61 return $this->entityTypeManager->getHandler($entity_type_id, 'translation');
46 } 62 }
47 63
48 /** 64 /**
49 * {@inheritdoc} 65 * {@inheritdoc}
50 */ 66 */
57 73
58 /** 74 /**
59 * {@inheritdoc} 75 * {@inheritdoc}
60 */ 76 */
61 public function isSupported($entity_type_id) { 77 public function isSupported($entity_type_id) {
62 $entity_type = $this->entityManager->getDefinition($entity_type_id); 78 $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
63 return $entity_type->isTranslatable() && ($entity_type->hasLinkTemplate('drupal:content-translation-overview') || $entity_type->get('content_translation_ui_skip')); 79 return $entity_type->isTranslatable() && ($entity_type->hasLinkTemplate('drupal:content-translation-overview') || $entity_type->get('content_translation_ui_skip'));
64 } 80 }
65 81
66 /** 82 /**
67 * {@inheritdoc} 83 * {@inheritdoc}
68 */ 84 */
69 public function getSupportedEntityTypes() { 85 public function getSupportedEntityTypes() {
70 $supported_types = []; 86 $supported_types = [];
71 foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { 87 foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
72 if ($this->isSupported($entity_type_id)) { 88 if ($this->isSupported($entity_type_id)) {
73 $supported_types[$entity_type_id] = $entity_type; 89 $supported_types[$entity_type_id] = $entity_type;
74 } 90 }
75 } 91 }
76 return $supported_types; 92 return $supported_types;
80 * {@inheritdoc} 96 * {@inheritdoc}
81 */ 97 */
82 public function setEnabled($entity_type_id, $bundle, $value) { 98 public function setEnabled($entity_type_id, $bundle, $value) {
83 $config = $this->loadContentLanguageSettings($entity_type_id, $bundle); 99 $config = $this->loadContentLanguageSettings($entity_type_id, $bundle);
84 $config->setThirdPartySetting('content_translation', 'enabled', $value)->save(); 100 $config->setThirdPartySetting('content_translation', 'enabled', $value)->save();
85 $entity_type = $this->entityManager->getDefinition($entity_type_id);
86 $this->updatesManager->updateDefinitions([$entity_type_id => $entity_type]);
87 } 101 }
88 102
89 /** 103 /**
90 * {@inheritdoc} 104 * {@inheritdoc}
91 */ 105 */
92 public function isEnabled($entity_type_id, $bundle = NULL) { 106 public function isEnabled($entity_type_id, $bundle = NULL) {
93 $enabled = FALSE; 107 $enabled = FALSE;
94 108
95 if ($this->isSupported($entity_type_id)) { 109 if ($this->isSupported($entity_type_id)) {
96 $bundles = !empty($bundle) ? [$bundle] : array_keys($this->entityManager->getBundleInfo($entity_type_id)); 110 $bundles = !empty($bundle) ? [$bundle] : array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id));
97 foreach ($bundles as $bundle) { 111 foreach ($bundles as $bundle) {
98 $config = $this->loadContentLanguageSettings($entity_type_id, $bundle); 112 $config = $this->loadContentLanguageSettings($entity_type_id, $bundle);
99 if ($config->getThirdPartySetting('content_translation', 'enabled', FALSE)) { 113 if ($config->getThirdPartySetting('content_translation', 'enabled', FALSE)) {
100 $enabled = TRUE; 114 $enabled = TRUE;
101 break; 115 break;
137 */ 151 */
138 protected function loadContentLanguageSettings($entity_type_id, $bundle) { 152 protected function loadContentLanguageSettings($entity_type_id, $bundle) {
139 if ($entity_type_id == NULL || $bundle == NULL) { 153 if ($entity_type_id == NULL || $bundle == NULL) {
140 return NULL; 154 return NULL;
141 } 155 }
142 $config = $this->entityManager->getStorage('language_content_settings')->load($entity_type_id . '.' . $bundle); 156 $config = $this->entityTypeManager->getStorage('language_content_settings')->load($entity_type_id . '.' . $bundle);
143 if ($config == NULL) { 157 if ($config == NULL) {
144 $config = $this->entityManager->getStorage('language_content_settings')->create(['target_entity_type_id' => $entity_type_id, 'target_bundle' => $bundle]); 158 $config = $this->entityTypeManager->getStorage('language_content_settings')->create(['target_entity_type_id' => $entity_type_id, 'target_bundle' => $bundle]);
145 } 159 }
146 return $config; 160 return $config;
147 } 161 }
148 162
149 /** 163 /**