本文整理汇总了PHP中eZ\Publish\API\Repository\Values\Content\Content::getField方法的典型用法代码示例。如果您正苦于以下问题:PHP Content::getField方法的具体用法?PHP Content::getField怎么用?PHP Content::getField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZ\Publish\API\Repository\Values\Content\Content
的用法示例。
在下文中一共展示了Content::getField方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFieldValue
/**
* Returns parsed field value.
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
* @param string $field
* @param string $language
*
* @return array
*/
public function getFieldValue(Content $content, $field, $language)
{
$fieldObj = $content->getField($field, $language);
$contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId);
$imageFieldIdentifier = $this->getImageFieldIdentifier($content->id, $language);
$relatedContentId = $this->getRelation($content, $fieldObj->fieldDefIdentifier, $language);
$mapping = $this->relationMapper->getMapping($contentType->identifier, $field);
try {
if ($relatedContentId && $mapping) {
$relatedContent = $this->contentService->loadContent($relatedContentId);
if ($relatedContent && $relatedContent->versionInfo->contentInfo->published) {
$relatedContentType = $this->contentTypeService->loadContentType($relatedContent->contentInfo->contentTypeId);
if ($relatedContentType->identifier != $mapping['content']) {
throw new InvalidRelationException(sprintf("Invalid relation: field '%s:%s' (object: %s, field: %s) has improper relation to object '%s' (object: %s) but '%s:%s' expected.", $contentType->identifier, $field, $content->id, $fieldObj->id, $relatedContentType->identifier, $relatedContentId, $mapping['content'], $mapping['field']));
}
$relatedField = $content->getField($mapping['field'], $language);
$value = $relatedField ? $this->getParsedFieldValue($relatedField, $relatedContent, $language, $imageFieldIdentifier) : '';
} else {
$value = '';
}
} else {
$value = $fieldObj ? $this->getParsedFieldValue($fieldObj, $content, $language, $imageFieldIdentifier) : '';
}
} catch (InvalidRelationException $exception) {
$this->logger->warning($exception->getMessage());
$value = '';
}
return array('key' => $field, 'value' => $value);
}
示例2: getField
/**
* This method returns the field for a given field definition identifier and language
*
* If not set the initialLanguage of the content version is used.
*
* @param string $fieldDefIdentifier
* @param string|null $languageCode
*
* @return \eZ\Publish\API\Repository\Values\Content\Field|null A {@link Field} or null if nothing is found
*/
public function getField($fieldDefIdentifier, $languageCode = null)
{
return $this->content->getField($fieldDefIdentifier, $languageCode);
}
示例3: getTranslatedField
/**
* Returns Field object in the appropriate language for a given content.
* By default, this method will return the field in current language if translation is present. If not, main language will be used.
* If $forcedLanguage is provided, will return the field in this language, if translation is present.
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
* @param string $fieldDefIdentifier Field definition identifier.
* @param string $forcedLanguage Locale we want the field translation in (e.g. "fre-FR"). Null by default (takes current locale)
*
* @return \eZ\Publish\API\Repository\Values\Content\Field|null
*/
public function getTranslatedField(Content $content, $fieldDefIdentifier, $forcedLanguage = null)
{
if ($forcedLanguage !== null) {
$languages = array($forcedLanguage);
} else {
$languages = $this->configResolver->getParameter('languages');
}
// Always add null as last entry so that we can use it pass it as languageCode $content->getField(),
// forcing to use the main language if all others fail.
$languages[] = null;
// Loop over prioritized languages to get the appropriate translated field.
foreach ($languages as $lang) {
$field = $content->getField($fieldDefIdentifier, $lang);
if ($field instanceof Field) {
return $field;
}
}
}
示例4: getTranslatedField
/**
* Returns Field object in the appropriate language for a given content.
* By default, this method will return the field in current language if translation is present. If not, main language will be used.
* If $forcedLanguage is provided, will return the field in this language, if translation is present.
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
* @param string $fieldDefIdentifier Field definition identifier.
* @param string $forcedLanguage Locale we want the field translation in (e.g. "fre-FR"). Null by default (takes current locale)
*
* @return \eZ\Publish\API\Repository\Values\Content\Field|null
*/
public function getTranslatedField(Content $content, $fieldDefIdentifier, $forcedLanguage = null)
{
// Loop over prioritized languages to get the appropriate translated field.
foreach ($this->getLanguages($forcedLanguage) as $lang) {
$field = $content->getField($fieldDefIdentifier, $lang);
if ($field instanceof Field) {
return $field;
}
}
}