当前位置: 首页>>代码示例>>PHP>>正文


PHP Content::getField方法代码示例

本文整理汇总了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);
 }
开发者ID:sdaoudi,项目名称:EzSystemsRecommendationBundle,代码行数:38,代码来源:Value.php

示例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);
 }
开发者ID:blankse,项目名称:ezpublish-kernel-1,代码行数:14,代码来源:User.php

示例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;
         }
     }
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:29,代码来源:TranslationHelper.php

示例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;
         }
     }
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:21,代码来源:TranslationHelper.php


注:本文中的eZ\Publish\API\Repository\Values\Content\Content::getField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。