1 | <?php |
||
26 | class TranslationHelper |
||
27 | { |
||
28 | /** |
||
29 | * @var \eZ\Publish\Core\MVC\ConfigResolverInterface |
||
30 | */ |
||
31 | protected $configResolver; |
||
32 | |||
33 | /** |
||
34 | * @var \eZ\Publish\API\Repository\ContentService |
||
35 | */ |
||
36 | protected $contentService; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | private $siteAccessesByLanguage; |
||
42 | |||
43 | /** |
||
44 | * @var \Psr\Log\LoggerInterface |
||
45 | */ |
||
46 | private $logger; |
||
47 | |||
48 | public function __construct(ConfigResolverInterface $configResolver, ContentService $contentService, array $siteAccessesByLanguage, LoggerInterface $logger = null) |
||
55 | |||
56 | /** |
||
57 | * Returns content name, translated. |
||
58 | * By default this method uses prioritized languages, unless $forcedLanguage is provided. |
||
59 | * |
||
60 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
61 | * @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale) |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | public function getTranslatedContentName(Content $content, $forcedLanguage = null) |
||
72 | |||
73 | /** |
||
74 | * Returns content name, translated, from a VersionInfo object. |
||
75 | * By default this method uses prioritized languages, unless $forcedLanguage is provided. |
||
76 | * |
||
77 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
78 | * @param string $forcedLanguage |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | private function getTranslatedContentNameByVersionInfo(VersionInfo $versionInfo, $forcedLanguage = null) |
||
93 | |||
94 | /** |
||
95 | * Returns content name, translated, from a ContentInfo object. |
||
96 | * By default this method uses prioritized languages, unless $forcedLanguage is provided. |
||
97 | * |
||
98 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
99 | * @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale) |
||
100 | * |
||
101 | * @todo Remove ContentService usage when translated names are available in ContentInfo (see https://jira.ez.no/browse/EZP-21755) |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getTranslatedContentNameByContentInfo(ContentInfo $contentInfo, $forcedLanguage = null) |
||
116 | |||
117 | /** |
||
118 | * Returns Field object in the appropriate language for a given content. |
||
119 | * By default, this method will return the field in current language if translation is present. If not, main language will be used. |
||
120 | * If $forcedLanguage is provided, will return the field in this language, if translation is present. |
||
121 | * |
||
122 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
123 | * @param string $fieldDefIdentifier Field definition identifier. |
||
124 | * @param string $forcedLanguage Locale we want the field translation in (e.g. "fre-FR"). Null by default (takes current locale) |
||
125 | * |
||
126 | * @return \eZ\Publish\API\Repository\Values\Content\Field|null |
||
127 | */ |
||
128 | public function getTranslatedField(Content $content, $fieldDefIdentifier, $forcedLanguage = null) |
||
138 | |||
139 | /** |
||
140 | * Returns Field definition name in the appropriate language for a given content. |
||
141 | * |
||
142 | * By default, this method will return the field definition name in current language if translation is present. If not, main language will be used. |
||
143 | * If $forcedLanguage is provided, will return the field definition name in this language, if translation is present. |
||
144 | * |
||
145 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
146 | * @param string $fieldDefIdentifier Field Definition identifier |
||
147 | * @param string $property Specifies if 'name' or 'description' should be used |
||
148 | * @param string $forcedLanguage Locale we want the field definition name translated in in (e.g. "fre-FR"). Null by default (takes current locale) |
||
149 | * |
||
150 | * @throws InvalidArgumentException |
||
151 | * |
||
152 | * @return string|null |
||
153 | */ |
||
154 | public function getTranslatedFieldDefinitionProperty( |
||
181 | |||
182 | /** |
||
183 | * Gets translated property generic helper. |
||
184 | * |
||
185 | * For generic use, expects array property as-is on value object, typically $object->$property[$language] |
||
186 | * |
||
187 | * Languages will consist of either forced language or current languages list, in addition helper will check if for |
||
188 | * mainLanguage property and append that to languages if alwaysAvailable property is true or non-existing. |
||
189 | * |
||
190 | * @param \eZ\Publish\API\Repository\Values\ValueObject $object Can be any kid of Value object which directly holds the translated property |
||
191 | * @param string $property Property name, example 'names', 'descriptions' |
||
192 | * @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale) |
||
193 | * |
||
194 | * @throws InvalidArgumentException |
||
195 | * |
||
196 | * @return string|null |
||
197 | */ |
||
198 | public function getTranslatedByProperty(ValueObject $object, $property, $forcedLanguage = null) |
||
220 | |||
221 | /** |
||
222 | * Gets translated method generic helper. |
||
223 | * |
||
224 | * For generic use, expects method exposing translated property as-is on value object, typically $object->$method($language) |
||
225 | * |
||
226 | * Languages will consist of either forced language or current languages list, in addition helper will append null |
||
227 | * to list of languages so method may fallback to main/initial language if supported by domain. |
||
228 | * |
||
229 | * @param \eZ\Publish\API\Repository\Values\ValueObject $object Can be any kind of Value object which directly holds the methods that provides translated value. |
||
230 | * @param string $method Method name, example 'getName', 'description' |
||
231 | * @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale) |
||
232 | * |
||
233 | * @throws InvalidArgumentException |
||
234 | * |
||
235 | * @return string|null |
||
236 | */ |
||
237 | public function getTranslatedByMethod(ValueObject $object, $method, $forcedLanguage = null) |
||
249 | |||
250 | /** |
||
251 | * Returns a SiteAccess name for translation in $languageCode. |
||
252 | * This is used for LanguageSwitcher feature (generate links for current content in a different language if available). |
||
253 | * Will use configured translation_siteaccesses if any. Otherwise will use related siteaccesses (e.g. same repository, same rootLocationId). |
||
254 | * |
||
255 | * Will return null if no translation SiteAccess can be found. |
||
256 | * |
||
257 | * @param string $languageCode Translation language code. |
||
258 | * |
||
259 | * @return string|null |
||
260 | */ |
||
261 | public function getTranslationSiteAccess($languageCode) |
||
279 | |||
280 | /** |
||
281 | * Returns the list of all available languages, including the ones configured in related SiteAccesses. |
||
282 | * |
||
283 | * @return array |
||
284 | */ |
||
285 | public function getAvailableLanguages() |
||
302 | |||
303 | /** |
||
304 | * @param string|null $forcedLanguage |
||
305 | * @param string|null $fallbackLanguage |
||
306 | * |
||
307 | * @return array|mixed |
||
308 | */ |
||
309 | private function getLanguages($forcedLanguage = null, $fallbackLanguage = null) |
||
323 | } |
||
324 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.