本文整理汇总了PHP中eZ\Publish\API\Repository\ContentTypeService::newFieldDefinitionCreateStruct方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentTypeService::newFieldDefinitionCreateStruct方法的具体用法?PHP ContentTypeService::newFieldDefinitionCreateStruct怎么用?PHP ContentTypeService::newFieldDefinitionCreateStruct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZ\Publish\API\Repository\ContentTypeService
的用法示例。
在下文中一共展示了ContentTypeService::newFieldDefinitionCreateStruct方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: visit
/**
* @inheritdoc
*/
public function visit(TreeNodeInterface $node, &$data)
{
$struct = $this->contentTypeService->newFieldDefinitionCreateStruct('', '');
$this->fillValueObject($struct, $data);
// Get position from node index (starts from 1)
$struct->position = $node->getIndex() + 1;
return $struct;
}
示例2: newFieldDefinitionCreateStruct
/**
* Instantiates a field definition create struct
*
* @param string $fieldTypeIdentifier the required field type identifier
* @param string $identifier the required identifier for the field definition
*
* @return \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct
*/
public function newFieldDefinitionCreateStruct($identifier, $fieldTypeIdentifier)
{
return $this->service->newFieldDefinitionCreateStruct($identifier, $fieldTypeIdentifier);
}
示例3: parse
/**
* Parse input structure.
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser If an error is found while parsing
*
* @return \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
if (!array_key_exists('identifier', $data)) {
throw new Exceptions\Parser("Missing 'identifier' element for FieldDefinitionCreate.");
}
if (!array_key_exists('fieldType', $data)) {
throw new Exceptions\Parser("Missing 'fieldType' element for FieldDefinitionCreate.");
}
$fieldDefinitionCreate = $this->contentTypeService->newFieldDefinitionCreateStruct($data['identifier'], $data['fieldType']);
// @todo XSD says that descriptions is mandatory, but content type can be created without it
if (array_key_exists('names', $data)) {
if (!is_array($data['names']) || !array_key_exists('value', $data['names']) || !is_array($data['names']['value'])) {
throw new Exceptions\Parser("Invalid 'names' element for FieldDefinitionCreate.");
}
$fieldDefinitionCreate->names = $this->parserTools->parseTranslatableList($data['names']);
}
// @todo XSD says that descriptions is mandatory, but content type can be created without it
if (array_key_exists('descriptions', $data)) {
if (!is_array($data['descriptions']) || !array_key_exists('value', $data['descriptions']) || !is_array($data['descriptions']['value'])) {
throw new Exceptions\Parser("Invalid 'descriptions' element for FieldDefinitionCreate.");
}
$fieldDefinitionCreate->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']);
}
// @todo XSD says that fieldGroup is mandatory, but content type can be created without it
if (array_key_exists('fieldGroup', $data)) {
$fieldDefinitionCreate->fieldGroup = $data['fieldGroup'];
}
// @todo XSD says that position is mandatory, but content type can be created without it
if (array_key_exists('position', $data)) {
$fieldDefinitionCreate->position = (int) $data['position'];
}
// @todo XSD says that isTranslatable is mandatory, but content type can be created without it
if (array_key_exists('isTranslatable', $data)) {
$fieldDefinitionCreate->isTranslatable = $this->parserTools->parseBooleanValue($data['isTranslatable']);
}
// @todo XSD says that isRequired is mandatory, but content type can be created without it
if (array_key_exists('isRequired', $data)) {
$fieldDefinitionCreate->isRequired = $this->parserTools->parseBooleanValue($data['isRequired']);
}
// @todo XSD says that isInfoCollector is mandatory, but content type can be created without it
if (array_key_exists('isInfoCollector', $data)) {
$fieldDefinitionCreate->isInfoCollector = $this->parserTools->parseBooleanValue($data['isInfoCollector']);
}
// @todo XSD says that isSearchable is mandatory, but content type can be created without it
if (array_key_exists('isSearchable', $data)) {
$fieldDefinitionCreate->isSearchable = $this->parserTools->parseBooleanValue($data['isSearchable']);
}
// @todo XSD says that defaultValue is mandatory, but content type can be created without it
if (array_key_exists('defaultValue', $data)) {
try {
$fieldDefinitionCreate->defaultValue = $this->fieldTypeParser->parseValue($data['fieldType'], $data['defaultValue']);
} catch (Exception $e) {
throw new Exceptions\Parser("Invalid 'defaultValue' element for FieldDefinitionCreate.", 0, $e);
}
}
if (array_key_exists('validatorConfiguration', $data)) {
$fieldDefinitionCreate->validatorConfiguration = $this->fieldTypeParser->parseValidatorConfiguration($data['fieldType'], $data['validatorConfiguration']);
}
if (array_key_exists('fieldSettings', $data)) {
$fieldDefinitionCreate->fieldSettings = $this->fieldTypeParser->parseFieldSettings($data['fieldType'], $data['fieldSettings']);
}
return $fieldDefinitionCreate;
}
示例4: createFieldDefinition
/**
* Helper function to create field definitions based to be added to a new/existing content type.
*
* @todo Add translation support if needed
* @param ContentTypeService $contentTypeService
* @param array $attribute
* @return \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct
* @throws \Exception
*/
private function createFieldDefinition(ContentTypeService $contentTypeService, array $attribute)
{
if (!isset($attribute['identifier']) || !isset($attribute['type'])) {
throw new \Exception("Keys 'type' and 'identifier' are mandatory to define a new field in a field type");
}
$fieldDefinition = $contentTypeService->newFieldDefinitionCreateStruct($attribute['identifier'], $attribute['type']);
foreach ($attribute as $key => $value) {
switch ($key) {
case 'name':
$fieldDefinition->names = array($this->getLanguageCode() => $value);
break;
case 'description':
$fieldDefinition->descriptions = array($this->getLanguageCode() => $value);
break;
case 'required':
$fieldDefinition->isRequired = $value;
break;
case 'searchable':
$fieldDefinition->isSearchable = $value;
break;
case 'info-collector':
$fieldDefinition->isInfoCollector = $value;
break;
case 'disable-translation':
$fieldDefinition->isTranslatable = !$value;
break;
case 'category':
$fieldDefinition->fieldGroup = $value == 'default' ? 'content' : $value;
break;
case 'default-value':
$fieldDefinition->defaultValue = $value;
break;
case 'field-settings':
$fieldDefinition->fieldSettings = $this->getFieldSettings($value);
break;
case 'validator-configuration':
$fieldDefinition->validatorConfiguration = $value;
break;
}
}
return $fieldDefinition;
}