public getTranslatedByMethod ( eZ\Publish\API\Repository\Values\ValueObject $object, string $method, string $forcedLanguage = null ) : string | null | ||
$object | eZ\Publish\API\Repository\Values\ValueObject | Can be any kind of Value object which directly holds the methods that provides translated value. |
$method | string | Method name, example 'getName', 'description' |
$forcedLanguage | string | Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale) |
Результат | string | null |
public function getTranslatedByMethod(ValueObject $object, $method, $forcedLanguage = null)
{
if (!method_exists($object, $method)) {
throw new InvalidArgumentException('$method', "Method '{$method}' not found on " . get_class($object));
}
foreach ($this->getLanguages($forcedLanguage) as $lang) {
if ($value = $object->{$method}($lang)) {
return $value;
}
}
}
/** * Returns tag keyword for provided tag ID or tag object. * * @param mixed|\Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag * * @return string */ public function getTagKeyword($tag) { if (!$tag instanceof Tag) { try { $tag = $this->tagsService->loadTag($tag); } catch (NotFoundException $e) { return ''; } } return $this->translationHelper->getTranslatedByMethod($tag, 'getKeyword'); }