本文整理汇总了PHP中eZ\Publish\API\Repository\Values\Content\Content类的典型用法代码示例。如果您正苦于以下问题:PHP Content类的具体用法?PHP Content怎么用?PHP Content使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Content类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findFieldInContent
/**
* Finds the field with id $fieldId in $content.
*
* @param int $fieldId
* @param Content $content
*
* @return Field
*/
protected function findFieldInContent($fieldId, Content $content)
{
foreach ($content->getFields() as $field) {
if ($field->id == $fieldId) {
return $field;
}
}
throw new InvalidArgumentException("Field with id {$fieldId} not found in Content with id {$content->id}");
}
示例2: mapContent
/**
* Maps Repository Content to the Site Content.
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
* @param string $languageCode
*
* @return \Netgen\EzPlatformSiteApi\Core\Site\Values\Content
*/
public function mapContent(APIContent $content, $languageCode)
{
$contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId);
$fields = $content->getFieldsByLanguage($languageCode);
$fieldsData = [];
foreach ($fields as $field) {
$fieldsData[] = $this->mapFieldData($field, $contentType);
}
return new Content(['_fields_data' => $fieldsData, 'contentInfo' => $this->mapContentInfo($content->versionInfo, $languageCode, $contentType), 'innerContent' => $content]);
}
示例3: castContent
public function castContent(Content $content, array $a, Stub $stub, $isNested, $filter = 0)
{
$info = $content->contentInfo;
$a = [Caster::PREFIX_VIRTUAL . 'id' => $info->id, Caster::PREFIX_VIRTUAL . 'name' => $info->name] + $a;
if (!$filter & Caster::EXCLUDE_VERBOSE) {
$groupedFields = [];
foreach ($content->getFields() as $field) {
$groupedFields[$field->languageCode][$field->fieldDefIdentifier] = $field->value;
}
$a += [Caster::PREFIX_VIRTUAL . 'names' => $content->versionInfo->getNames(), Caster::PREFIX_VIRTUAL . 'contentInfo' => $info, Caster::PREFIX_VIRTUAL . 'fields' => $groupedFields];
}
return $a;
}
示例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)
{
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;
}
}
}
示例5: testUpdateContentMetadataNotUpdatesContentVersion
/**
* Test for the updateContentMetadata() method.
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
*
* @return void
* @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata()
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
*/
public function testUpdateContentMetadataNotUpdatesContentVersion($content)
{
$this->assertEquals(1, $content->getVersionInfo()->versionNo);
}
示例6: assertCopyContentValues
/**
* Asserts that $copiedContent is valid copy of $originalContent
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $originalContent
* @param \eZ\Publish\API\Repository\Values\Content\Content $copiedContent
*/
protected function assertCopyContentValues(APIContent $originalContent, APIContent $copiedContent)
{
$this->assertNotEquals($originalContent->id, $copiedContent->id, "Id of content copy is equal to id od original content");
$this->assertSameClassPropertiesCorrect(array("contentTypeId", "sectionId", "published", "ownerId", "alwaysAvailable", "mainLanguageCode"), $originalContent->contentInfo, $copiedContent->contentInfo);
$this->assertNotEquals($originalContent->contentInfo->id, $copiedContent->contentInfo->id);
$this->assertNotEquals($originalContent->contentInfo->remoteId, $copiedContent->contentInfo->remoteId);
$this->assertSameClassPropertiesCorrect(array("versionNo", "names", "creatorId", "initialLanguageCode", "languageCodes"), $originalContent->versionInfo, $copiedContent->versionInfo);
$this->assertNotEquals($originalContent->versionInfo->id, $copiedContent->versionInfo->id);
$originalFields = $originalContent->getFields();
$copiedFields = $copiedContent->getFields();
$this->assertCount(count($originalFields), $copiedFields, "Count of fields copied does not match the count of original fields");
foreach ($originalFields as $fieldIndex => $originalField) {
$this->assertSameClassPropertiesCorrect(array("fieldDefIdentifier", "value", "languageCode"), $originalField, $copiedFields[$fieldIndex]);
$this->assertNotEquals($originalField->id, $copiedFields[$fieldIndex]->id);
}
}
示例7: ezobjectrelation
/**
* Method for parsing ezobjectrelation field.
* For now related fields refer to images.
*
* @param \eZ\Publish\API\Repository\Values\Content\Field $field
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
* @param string $language
* @param string $imageFieldIdentifier
*
* @return string
*/
public function ezobjectrelation(Field $field, Content $content, $language, $imageFieldIdentifier)
{
$fields = $content->getFieldsByLanguage($language);
foreach ($fields as $type => $field) {
if ($type == $imageFieldIdentifier) {
return $this->ezimage($field, $content);
}
}
return '';
}
示例8: assertCopyContentValues
/**
* Asserts that $copiedContent is valid copy of $originalContent.
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $originalContent
* @param \eZ\Publish\API\Repository\Values\Content\Content $copiedContent
*/
protected function assertCopyContentValues(APIContent $originalContent, APIContent $copiedContent)
{
$this->assertNotEquals($originalContent->id, $copiedContent->id, 'Id of content copy is equal to id od original content');
$this->assertSameClassPropertiesCorrect(array('contentTypeId', 'sectionId', 'published', 'ownerId', 'alwaysAvailable', 'mainLanguageCode'), $originalContent->contentInfo, $copiedContent->contentInfo);
$this->assertNotEquals($originalContent->contentInfo->id, $copiedContent->contentInfo->id);
$this->assertNotEquals($originalContent->contentInfo->remoteId, $copiedContent->contentInfo->remoteId);
$this->assertSameClassPropertiesCorrect(array('versionNo', 'names', 'creatorId', 'initialLanguageCode', 'languageCodes'), $originalContent->versionInfo, $copiedContent->versionInfo);
$this->assertNotEquals($originalContent->versionInfo->id, $copiedContent->versionInfo->id);
$originalFields = $originalContent->getFields();
$copiedFields = $copiedContent->getFields();
$this->assertCount(count($originalFields), $copiedFields, 'Count of fields copied does not match the count of original fields');
foreach ($originalFields as $fieldIndex => $originalField) {
$this->assertSameClassPropertiesCorrect(array('fieldDefIdentifier', 'value', 'languageCode'), $originalField, $copiedFields[$fieldIndex]);
$this->assertNotEquals($originalField->id, $copiedFields[$fieldIndex]->id);
}
}
示例9: getFieldTypeIdentifier
/**
* Returns the field type identifier for $field
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
* @param \eZ\Publish\API\Repository\Values\Content\Field $field
*
* @return string
*/
protected function getFieldTypeIdentifier(Content $content, Field $field)
{
$contentInfo = $content->getVersionInfo()->getContentInfo();
$key = $contentInfo->contentTypeId . ' ' . $field->fieldDefIdentifier;
if (!isset($this->fieldTypeIdentifiers[$key])) {
$contentType = $this->repository->getContentTypeService()->loadContentType($contentInfo->contentTypeId);
$this->fieldTypeIdentifiers[$key] = $contentType->getFieldDefinition($field->fieldDefIdentifier)->fieldTypeIdentifier;
}
return $this->fieldTypeIdentifiers[$key];
}
示例10: __get
public function __get($property)
{
switch ($property) {
case 'contentInfo':
return $this->getContentInfo();
case 'versionInfo':
return $this->getVersionInfo();
}
return parent::__get($property);
}
示例11: renderContent
/**
* Renders $content by selecting the right template.
* $content will be injected in the selected template.
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
* @param string $viewType Variation of display for your content. Default is 'full'.
* @param array $parameters Parameters to pass to the template called to
* render the view. By default, it's empty. 'content' entry is
* reserved for the Content that is rendered.
* @throws \RuntimeException
*
* @return string
*/
public function renderContent(Content $content, $viewType = ViewManagerInterface::VIEW_TYPE_FULL, $parameters = array())
{
$contentInfo = $content->getVersionInfo()->getContentInfo();
foreach ($this->getAllContentViewProviders() as $viewProvider) {
$view = $viewProvider->getView($contentInfo, $viewType);
if ($view instanceof ContentViewInterface) {
$parameters['content'] = $content;
return $this->renderContentView($view, $parameters);
}
}
throw new RuntimeException("Unable to find a template for #{$contentInfo->id}");
}
示例12: getAuthor
/**
* Returns author of the content.
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $contentValue
* @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
*
* @return string
*/
private function getAuthor(Content $contentValue, ContentType $contentType)
{
$author = $contentValue->getFieldValue($this->value->getConfiguredFieldIdentifier('author', $contentType));
if (null === $author) {
$ownerId = empty($contentValue->contentInfo->ownerId) ? $this->defaultAuthorId : $contentValue->contentInfo->ownerId;
$userContentInfo = $this->contentService->loadContentInfo($ownerId);
$author = $userContentInfo->name;
}
return (string) $author;
}
示例13: getRelation
/**
* Checks if content has image relation field, returns its ID if true.
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
* @param string $field
* @param string $language
*
* @return int|null
*/
private function getRelation(Content $content, $field, $language)
{
$fieldDefinitions = $this->getFieldDefinitionList();
$fieldNames = array_flip($fieldDefinitions);
$isRelation = in_array('ezobjectrelation', $fieldDefinitions) && $field == $fieldNames['ezobjectrelation'];
if ($isRelation && $field == $fieldNames['ezobjectrelation']) {
$fieldValue = $content->getFieldValue($fieldNames['ezobjectrelation'], $language);
if (isset($fieldValue->destinationContentId)) {
return $fieldValue->destinationContentId;
}
}
return null;
}
示例14: renderPreview
/**
* Returns preview for $content (versionNo to display is held in $content->versionInfo).
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
* @param array $params Hash of arbitrary parameters to pass to final view
* @param \eZ\Publish\Core\MVC\Legacy\Templating\LegacyHelper $legacyHelper
*
* @return string
*/
public function renderPreview(APIContent $content, array $params, LegacyHelper $legacyHelper)
{
/** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess $siteAccess */
$siteAccess = $this->getCurrentRequest()->attributes->get('siteaccess');
$moduleResult = array();
// Filling up moduleResult
$result = $this->getLegacyKernel()->runCallback(function () use($content, $params, $siteAccess, &$moduleResult) {
$contentViewModule = eZModule::findModule('content');
$moduleResult = $contentViewModule->run('versionview', array($content->contentInfo->id, $content->getVersionInfo()->versionNo, $content->getVersionInfo()->languageCodes[0]), false, array('site_access' => $siteAccess->name) + $params);
return ezpEvent::getInstance()->filter('response/output', $moduleResult['content']);
}, false);
$legacyHelper->loadDataFromModuleResult($moduleResult);
return $result;
}
示例15: getFormSchemaFromContentObjectFields
/**
* reimp this function!
*
* Get and builds a form schema / entity from an content object with fields
*
* @param string $contentType
* @param string $languageCode
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
* @param bool $isCollector
*
* @return array $formSchemaArr,$formValueArr
*/
public function getFormSchemaFromContentObjectFields($contentType, $languageCode = 'eng-GB', $content = false, $isCollector = false)
{
$formValueArr = array();
$formSchemaArr = array();
$contentTypeConfig = false;
if (isset($this->config['frontendediting_config']['types'][$contentType->identifier])) {
$contentTypeConfig = $this->config['frontendediting_config']['types'][$contentType->identifier];
}
foreach ($contentType->getFieldDefinitions() as $field) {
if ($isCollector !== true || $isCollector === true && $field->isInfoCollector) {
if (!isset($contentTypeConfig['fields']) || in_array($field->identifier, $contentTypeConfig['fields'])) {
$fieldArr = array();
$fieldArr1 = false;
$fieldArr2 = false;
// $fieldArr['position'] = $field->position;
// TODO check if the name for a language code is set otherwise fall back
// maybe use ez
//var_dump( $field->names );
$fieldArr['label'] = $field->names[$languageCode];
$fieldArr['required'] = $field->isRequired;
$fieldArr['choices'] = false;
// map ez types to symfony types
// http://symfony.com/doc/current/reference/forms/types.html
// ToDo: to many
switch ($field->fieldTypeIdentifier) {
case 'ezstring':
$formFieldIdentifier = 'ezstring' . FormHandlerService::separator . $field->identifier;
$fieldArr['type'] = 'text';
$fieldArr['value'] = $field->defaultValue->text;
break;
case 'eztext':
$formFieldIdentifier = 'eztext' . FormHandlerService::separator . $field->identifier;
$fieldArr['type'] = 'textarea';
$fieldArr['value'] = $field->defaultValue->text;
break;
case 'ezxmltext':
$formFieldIdentifier = 'ezxmltext' . FormHandlerService::separator . $field->identifier;
$fieldArr['type'] = 'textarea';
// ToDo
// $fieldArr['value'] = $this->ezXmltextToHtml( $content, $field );
$fieldArr['value'] = '';
break;
case 'ezemail':
$formFieldIdentifier = 'ezemail' . FormHandlerService::separator . $field->identifier;
$fieldArr['type'] = 'email';
$fieldArr['value'] = $field->defaultValue->email;
break;
case 'ezboolean':
$formFieldIdentifier = 'ezxmltext' . FormHandlerService::separator . $field->identifier;
$fieldArr['type'] = 'checkbox';
$fieldArr['value'] = $field->defaultValue->bool;
break;
case 'ezuser':
// ToDo: many
$formFieldIdentifier = 'ezuser' . FormHandlerService::separator . $field->identifier . FormHandlerService::separator . 'login';
$fieldArr['type'] = 'text';
$fieldArr['label'] = 'cjw_publishtools.formbuilder.user.login';
$fieldArr['value'] = '';
$fieldArr1 = array();
$fieldArr1['type'] = 'email';
$fieldArr1['label'] = 'cjw_publishtools.formbuilder.user.email';
$fieldArr1['required'] = true;
$formFieldIdentifier1 = 'ezuser' . FormHandlerService::separator . $field->identifier . FormHandlerService::separator . 'email';
$fieldArr1['value'] = '';
$fieldArr1['choices'] = false;
$fieldArr2 = array();
$fieldArr2['type'] = 'password';
$fieldArr2['label'] = 'cjw_publishtools.formbuilder.user.password';
$fieldArr2['required'] = true;
$formFieldIdentifier2 = 'ezuser' . FormHandlerService::separator . $field->identifier . FormHandlerService::separator . 'password';
$fieldArr2['value'] = '';
$fieldArr2['choices'] = false;
break;
// ToDo: multiple / single, select / radio / checkbox, etc.
// ToDo: multiple / single, select / radio / checkbox, etc.
case 'ezselection':
$formFieldIdentifier = 'ezselection' . FormHandlerService::separator . $field->identifier;
$fieldArr['type'] = 'choice';
$fieldArr['choices'] = array();
// Translate choices, which aren't translatable in eZ BackEnd
foreach ($field->fieldSettings['options'] as $fieldChoiceKey => $fieldChoice) {
$fieldArr['choices'][$fieldChoiceKey] = $this->container->get('translator')->trans($fieldChoice);
}
// http://stackoverflow.com/questions/17314996/symfony2-array-to-string-conversion-error
if ($field->fieldSettings['isMultiple']) {
$fieldArr['multiple'] = true;
$fieldArr['value'] = $field->defaultValue->selection;
} else {
//.........这里部分代码省略.........