comparison core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.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
47 $langcode = $rendering_language; 47 $langcode = $rendering_language;
48 } 48 }
49 $renderer = 'ConfigurableLanguageRenderer'; 49 $renderer = 'ConfigurableLanguageRenderer';
50 } 50 }
51 $class = '\Drupal\views\Entity\Render\\' . $renderer; 51 $class = '\Drupal\views\Entity\Render\\' . $renderer;
52 $entity_type = $this->getEntityManager()->getDefinition($this->getEntityTypeId()); 52 $entity_type = $this->getEntityTypeManager()->getDefinition($this->getEntityTypeId());
53 $this->entityTranslationRenderer = new $class($view, $this->getLanguageManager(), $entity_type, $langcode); 53 $this->entityTranslationRenderer = new $class($view, $this->getLanguageManager(), $entity_type, $langcode);
54 } 54 }
55 return $this->entityTranslationRenderer; 55 return $this->entityTranslationRenderer;
56 } 56 }
57 57
72 // types. Below we apply language fallback to ensure a valid value is always 72 // types. Below we apply language fallback to ensure a valid value is always
73 // picked. 73 // picked.
74 $translation = $entity; 74 $translation = $entity;
75 if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) { 75 if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) {
76 $langcode = $this->getEntityTranslationRenderer()->getLangcode($row); 76 $langcode = $this->getEntityTranslationRenderer()->getLangcode($row);
77 $translation = $this->getEntityManager()->getTranslationFromContext($entity, $langcode); 77 $translation = $this->getEntityRepository()->getTranslationFromContext($entity, $langcode);
78 } 78 }
79 return $translation; 79 return $translation;
80 } 80 }
81 81
82 /** 82 /**
86 * The entity type identifier. 86 * The entity type identifier.
87 */ 87 */
88 abstract public function getEntityTypeId(); 88 abstract public function getEntityTypeId();
89 89
90 /** 90 /**
91 * Returns the entity manager. 91 * Returns the entity type manager.
92 * 92 *
93 * @return \Drupal\Core\Entity\EntityManagerInterface 93 * @return \Drupal\Core\Entity\EntityTypeManagerInterface
94 * The entity manager. 94 * The entity type manager.
95 */ 95 */
96 abstract protected function getEntityManager(); 96 protected function getEntityTypeManager() {
97 @trigger_error('Classes that use EntityTranslationRenderTrait must provide a getEntityTypeManager() method since drupal:8.7.0. This implementation will become abstract before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
98 return \Drupal::entityTypeManager();
99 }
100
101 /**
102 * Returns the entity repository.
103 *
104 * @return \Drupal\Core\Entity\EntityRepositoryInterface
105 * The entity repository.
106 */
107 protected function getEntityRepository() {
108 @trigger_error('Classes that use EntityTranslationRenderTrait must provide a getEntityRepository() method since drupal:8.7.0. This implementation will become abstract before drupal:9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
109 return \Drupal::service('entity.repository');
110 }
97 111
98 /** 112 /**
99 * Returns the language manager. 113 * Returns the language manager.
100 * 114 *
101 * @return \Drupal\Core\Language\LanguageManagerInterface 115 * @return \Drupal\Core\Language\LanguageManagerInterface