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
 /**
  * @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);
 }
Beispiel #2
0
 /**
  * Adds locations from $searchHit to $menu.
  *
  * @param ItemInterface $menu
  * @param SearchHit[] $searchHits
  */
 private function addLocationsToMenu(ItemInterface $menu, array $searchHits)
 {
     foreach ($searchHits as $searchHit) {
         /** @var Location $location */
         $location = $searchHit->valueObject;
         $menuItem = isset($menu[$location->parentLocationId]) ? $menu[$location->parentLocationId] : $menu;
         $menuItem->addChild($location->id, array('label' => $this->translationHelper->getTranslatedContentNameByContentInfo($location->contentInfo), 'uri' => $this->router->generate($location), 'attributes' => array('id' => 'nav-location-' . $location->id)));
         $menuItem->setChildrenAttribute('class', 'nav');
     }
 }
 public function testGetTranslatedNameByContentInfoForcedLanguageMainLanguage()
 {
     $name = 'Name in main language';
     $mainLanguage = 'eng-GB';
     $contentInfo = new ContentInfo(array('id' => 123, 'mainLanguageCode' => $mainLanguage, 'name' => $name));
     $this->configResolver->expects($this->never())->method('getParameter');
     $this->contentService->expects($this->never())->method('loadContentByContentInfo');
     $this->assertSame($name, $this->translationHelper->getTranslatedContentNameByContentInfo($contentInfo, $mainLanguage));
 }
 /**
  * Get the content name
  *
  * @param $contentId
  * @return string
  */
 public function getContentName($contentId)
 {
     $contentInfo = $this->contentService->loadContentInfo($contentId);
     return $this->translationHelper->getTranslatedContentNameByContentInfo($contentInfo);
 }