eZ\Publish\Core\Helper\TranslationHelper::getTranslatedContentNameByContentInfo PHP Method

getTranslatedContentNameByContentInfo() public method

By default this method uses prioritized languages, unless $forcedLanguage is provided.
public getTranslatedContentNameByContentInfo ( eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo, string $forcedLanguage = null ) : string
$contentInfo eZ\Publish\API\Repository\Values\Content\ContentInfo
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
return string
    public function getTranslatedContentNameByContentInfo(ContentInfo $contentInfo, $forcedLanguage = null)
    {
        if (isset($forcedLanguage) && $forcedLanguage === $contentInfo->mainLanguageCode) {
            return $contentInfo->name;
        }
        return $this->getTranslatedContentNameByVersionInfo($this->contentService->loadVersionInfo($contentInfo), $forcedLanguage);
    }

Usage Example

 /**
  * @param \eZ\Publish\API\Repository\Values\ValueObject $content Must be a valid Content or ContentInfo object.
  * @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
  *
  * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType When $content is not a valid Content or ContentInfo object.
  *
  * @return string
  */
 public function getTranslatedContentName(ValueObject $content, $forcedLanguage = null)
 {
     if ($content instanceof Content) {
         return $this->translationHelper->getTranslatedContentName($content, $forcedLanguage);
     } elseif ($content instanceof ContentInfo) {
         return $this->translationHelper->getTranslatedContentNameByContentInfo($content, $forcedLanguage);
     }
     throw new InvalidArgumentType('$content', 'eZ\\Publish\\API\\Repository\\Values\\Content\\Content or eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', $content);
 }
All Usage Examples Of eZ\Publish\Core\Helper\TranslationHelper::getTranslatedContentNameByContentInfo