Assume we want to get the translated value of a Text Line (ezstring) field with identifier title
.
$contentService = $this->get('ezpublish.api.service.content');
$content = $contentService->loadContent('<CONTENT-ID>');
$language = $content->versionInfo->initialLanguageCode;
$title = $content->fields['title'][$language]->text;
//Or
$title = $content->getFieldValue('title',$language)->text;
//similar to
$title = $content->getField('title',$language)->value->text;
$contentService = $this->get('ezpublish.api.service.content');
$content = $contentService->loadContent(<CONTENT-ID>);
$language = $content->versionInfo->initialLanguageCode;
$translationHelper = $this->get('ezpublish.translation_helper');
$title = $translationHelper->getTranslatedField($content, 'title', $language)->value->text;
$contentService = $this->get('ezpublish.api.service.content');
$content = $contentService->loadContent(<CONTENT-ID>);
$language = $content->versionInfo->initialLanguageCode;
$title = $content->getFieldsByLanguage($language)['title']->value->text;
loadVersionInfo()
contains only meta information about the current version. The content Fields data are not provided like above example.- This will just return the content name as defined in the
content name schema
.
$contentService = $this->get('ezpublish.api.service.content');
$contentInfo = $contentService->loadContentInfo(<CONTENT-ID>);
$contentInfoVersionInfo = $contentService->loadVersionInfo($contentInfo, $contentInfo->currentVersionNo);
$language = $contentInfoVersionInfo->initialLanguageCode;
$contentName = $contentInfoVersionInfo->getName($language);
This is similar to:
$contentService = $this->get('ezpublish.api.service.content');
$content = $contentService->loadContent(<CONTENT-ID>);
$language = $content->versionInfo->initialLanguageCode;
$contentName = $content->getName($language);