getTranslatedContentName() public method

By default this method uses prioritized languages, unless $forcedLanguage is provided.
public getTranslatedContentName ( eZ\Publish\API\Repository\Values\Content\Content $content, string $forcedLanguage = null ) : string
$content eZ\Publish\API\Repository\Values\Content\Content
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
return string
Exemplo n.º 1
0
 /**
  * @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);
 }
 public function testGetTranslatedNameForcedLanguage()
 {
     $content = $this->generateContent();
     $this->configResolver->expects($this->never())->method('getParameter');
     $this->assertSame('My name in english', $this->translationHelper->getTranslatedContentName($content, 'eng-GB'));
     $this->assertSame('Mon nom en français', $this->translationHelper->getTranslatedContentName($content, 'eng-US'));
 }