本文整理汇总了PHP中TYPO3\TYPO3CR\Domain\Service\Context::getNodeByIdentifier方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::getNodeByIdentifier方法的具体用法?PHP Context::getNodeByIdentifier怎么用?PHP Context::getNodeByIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\TYPO3CR\Domain\Service\Context
的用法示例。
在下文中一共展示了Context::getNodeByIdentifier方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProperty
/**
* Returns the specified property.
*
* If the node has a content object attached, the property will be fetched
* there if it is gettable.
*
* @param string $propertyName Name of the property
* @param boolean $returnNodesAsIdentifiers If enabled, references to nodes are returned as node identifiers instead of NodeData objects
* @return mixed value of the property
* @api
*/
public function getProperty($propertyName, $returnNodesAsIdentifiers = false)
{
$value = $this->nodeData->getProperty($propertyName);
if (!empty($value)) {
$nodeType = $this->getNodeType();
if ($nodeType->hasConfiguration('properties.' . $propertyName)) {
$expectedPropertyType = $nodeType->getPropertyType($propertyName);
switch ($expectedPropertyType) {
case 'references':
if ($returnNodesAsIdentifiers === false) {
$nodes = array();
foreach ($value as $nodeIdentifier) {
$node = $this->context->getNodeByIdentifier($nodeIdentifier);
// $node can be NULL if the node is not visible according to the current content context:
if ($node !== null) {
$nodes[] = $node;
}
}
$value = $nodes;
}
break;
case 'reference':
if ($returnNodesAsIdentifiers === false) {
$value = $this->context->getNodeByIdentifier($value);
}
break;
default:
$value = $this->propertyMapper->convert($value, $expectedPropertyType);
break;
}
}
}
return $value;
}
示例2: resolvePropertyReferences
/**
* Maps the property value (an array of node identifiers) to the Node objects if needed.
*
* @param array $value
* @return array
*/
protected function resolvePropertyReferences($value = [])
{
$nodes = array_map(function ($nodeIdentifier) {
return $this->context->getNodeByIdentifier($nodeIdentifier);
}, $value);
return array_filter($nodes);
}
示例3: setNodeProperties
/**
* Iterates through the given $properties setting them on the specified $node using the appropriate TypeConverters.
*
* @param object $nodeLike
* @param NodeType $nodeType
* @param array $properties
* @param TYPO3CRContext $context
* @param PropertyMappingConfigurationInterface $configuration
* @return void
* @throws TypeConverterException
*/
protected function setNodeProperties($nodeLike, NodeType $nodeType, array $properties, TYPO3CRContext $context, PropertyMappingConfigurationInterface $configuration = null)
{
$nodeTypeProperties = $nodeType->getProperties();
unset($properties['_lastPublicationDateTime']);
foreach ($properties as $nodePropertyName => $nodePropertyValue) {
if (substr($nodePropertyName, 0, 2) === '__') {
continue;
}
$nodePropertyType = isset($nodeTypeProperties[$nodePropertyName]['type']) ? $nodeTypeProperties[$nodePropertyName]['type'] : null;
switch ($nodePropertyType) {
case 'reference':
$nodePropertyValue = $context->getNodeByIdentifier($nodePropertyValue);
break;
case 'references':
$nodeIdentifiers = json_decode($nodePropertyValue);
$nodePropertyValue = array();
if (is_array($nodeIdentifiers)) {
foreach ($nodeIdentifiers as $nodeIdentifier) {
$referencedNode = $context->getNodeByIdentifier($nodeIdentifier);
if ($referencedNode !== null) {
$nodePropertyValue[] = $referencedNode;
}
}
} elseif ($nodeIdentifiers !== null) {
throw new TypeConverterException(sprintf('node type "%s" expects an array of identifiers for its property "%s"', $nodeType->getName(), $nodePropertyName), 1383587419);
}
break;
case 'DateTime':
if ($nodePropertyValue !== '' && ($nodePropertyValue = \DateTime::createFromFormat(\DateTime::W3C, $nodePropertyValue)) !== false) {
$nodePropertyValue->setTimezone(new \DateTimeZone(date_default_timezone_get()));
} else {
$nodePropertyValue = null;
}
break;
case 'integer':
$nodePropertyValue = intval($nodePropertyValue);
break;
case 'boolean':
if (is_string($nodePropertyValue)) {
$nodePropertyValue = $nodePropertyValue === 'true' ? true : false;
}
break;
case 'array':
$nodePropertyValue = json_decode($nodePropertyValue, true);
break;
}
if (substr($nodePropertyName, 0, 1) === '_') {
$nodePropertyName = substr($nodePropertyName, 1);
ObjectAccess::setProperty($nodeLike, $nodePropertyName, $nodePropertyValue);
continue;
}
if (!isset($nodeTypeProperties[$nodePropertyName])) {
if ($configuration !== null && $configuration->shouldSkipUnknownProperties()) {
continue;
} else {
throw new TypeConverterException(sprintf('Node type "%s" does not have a property "%s" according to the schema', $nodeType->getName(), $nodePropertyName), 1359552744);
}
}
$innerType = $nodePropertyType;
if ($nodePropertyType !== null) {
try {
$parsedType = TypeHandling::parseType($nodePropertyType);
$innerType = $parsedType['elementType'] ?: $parsedType['type'];
} catch (InvalidTypeException $exception) {
}
}
if (is_string($nodePropertyValue) && $this->objectManager->isRegistered($innerType) && $nodePropertyValue !== '') {
$nodePropertyValue = $this->propertyMapper->convert(json_decode($nodePropertyValue, true), $nodePropertyType, $configuration);
}
$nodeLike->setProperty($nodePropertyName, $nodePropertyValue);
}
}
示例4: getPersonProfile
/**
* @param string $personIdentifier
* @param Context $context
*
* @throws \Exception
*
* @return NodeInterface
*/
protected function getPersonProfile($personIdentifier, Context $context)
{
if ($personIdentifier === '') {
$person = $this->profileService->getCurrentPartyProfile();
} else {
$person = $context->getNodeByIdentifier($personIdentifier);
}
return $person;
}
示例5: setNodeProperties
/**
* Iterates through the given $properties setting them on the specified $node using the appropriate TypeConverters.
*
* @param object $nodeLike
* @param NodeType $nodeType
* @param array $properties
* @param \TYPO3\TYPO3CR\Domain\Service\Context $context
* @throws \TYPO3\Flow\Property\Exception\TypeConverterException
* @return void
*/
protected function setNodeProperties($nodeLike, NodeType $nodeType, array $properties, TYPO3CRContext $context)
{
$nodeTypeProperties = $nodeType->getProperties();
foreach ($properties as $nodePropertyName => $nodePropertyValue) {
if (substr($nodePropertyName, 0, 2) === '__') {
continue;
}
$nodePropertyType = isset($nodeTypeProperties[$nodePropertyName]['type']) ? $nodeTypeProperties[$nodePropertyName]['type'] : NULL;
switch ($nodePropertyType) {
case 'reference':
$nodePropertyValue = $context->getNodeByIdentifier($nodePropertyValue);
break;
case 'references':
$nodeIdentifiers = json_decode($nodePropertyValue);
$nodePropertyValue = array();
if (is_array($nodeIdentifiers)) {
foreach ($nodeIdentifiers as $nodeIdentifier) {
$referencedNode = $context->getNodeByIdentifier($nodeIdentifier);
if ($referencedNode !== NULL) {
$nodePropertyValue[] = $referencedNode;
}
}
} else {
throw new TypeConverterException(sprintf('node type "%s" expects an array of identifiers for its property "%s"', $nodeType->getName(), $nodePropertyName), 1383587419);
}
break;
case 'date':
if ($nodePropertyValue !== '') {
$nodePropertyValue = \DateTime::createFromFormat('!Y-m-d', $nodePropertyValue);
} else {
$nodePropertyValue = NULL;
}
break;
}
if (substr($nodePropertyName, 0, 1) === '_') {
$nodePropertyName = substr($nodePropertyName, 1);
ObjectAccess::setProperty($nodeLike, $nodePropertyName, $nodePropertyValue);
continue;
}
if (!isset($nodeTypeProperties[$nodePropertyName])) {
throw new TypeConverterException(sprintf('node type "%s" does not have a property "%s" according to the schema', $nodeType->getName(), $nodePropertyName), 1359552744);
}
if ($this->objectManager->isRegistered($nodePropertyType) && $nodePropertyValue !== '') {
$nodePropertyValue = $this->propertyMapper->convert(json_decode($nodePropertyValue, TRUE), $nodePropertyType);
}
$nodeLike->setProperty($nodePropertyName, $nodePropertyValue);
}
}
示例6: convertReferences
/**
* Convert raw value to references
*
* @param string $rawValue
* @param Context $context
* @return array<NodeInterface>
*/
protected function convertReferences($rawValue, Context $context)
{
$nodeIdentifiers = json_decode($rawValue);
$result = [];
if (is_array($nodeIdentifiers)) {
foreach ($nodeIdentifiers as $nodeIdentifier) {
$referencedNode = $context->getNodeByIdentifier($nodeIdentifier);
if ($referencedNode !== null) {
$result[] = $referencedNode;
}
}
}
return $result;
}