Skip to content

Commit d3f1f08

Browse files
author
Bernhard Schmitt
committed
FEATURE: Provide abstract PresentationObject and PresentationObjectFactory
1 parent dac5c96 commit d3f1f08

5 files changed

Lines changed: 242 additions & 1 deletion
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace PackageFactory\AtomicFusion\PresentationObjects\Fusion;
4+
5+
/*
6+
* This file is part of the PackageFactory.AtomicFusion.PresentationObjects package
7+
*/
8+
9+
/**
10+
* The generic abstract component presentation object implementation
11+
*/
12+
abstract class AbstractComponentPresentationObject implements ComponentPresentationObjectInterface
13+
{
14+
/**
15+
* Catches all internal EEL magic calls
16+
*
17+
* @param string $name
18+
* @param array $arguments
19+
*/
20+
final public function __call($name, $arguments)
21+
{
22+
throw new \BadMethodCallException( '"' . $name . '" is not part of the component API for ' . __CLASS__ . '. Please check your Fusion presentation component for typos.', 1578905708);
23+
}
24+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace PackageFactory\AtomicFusion\PresentationObjects\Fusion;
4+
5+
/*
6+
* This file is part of the PackageFactory.AtomicFusion.PresentationObjects package
7+
*/
8+
9+
use Neos\ContentRepository\Domain\NodeType\NodeTypeConstraintFactory;
10+
use Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface;
11+
use Neos\ContentRepository\Domain\Projection\Content\TraversableNodes;
12+
use Neos\Flow\Annotations as Flow;
13+
use Neos\Flow\I18n\Translator;
14+
use Neos\Neos\Service\ContentElementEditableService;
15+
use PackageFactory\AtomicFusion\PresentationObjects\Infrastructure\UriService;
16+
17+
/**
18+
* The generic abstract component presentation object factory implementation
19+
*/
20+
abstract class AbstractComponentPresentationObjectFactory implements ComponentPresentationObjectFactoryInterface
21+
{
22+
/**
23+
* @Flow\Inject
24+
* @var UriService
25+
*/
26+
protected $uriService;
27+
28+
/**
29+
* @Flow\Inject
30+
* @var Translator
31+
*/
32+
protected $translator;
33+
34+
/**
35+
* @Flow\Inject
36+
* @var ContentElementEditableService
37+
*/
38+
protected $contentElementEditableService;
39+
40+
/**
41+
* @Flow\Inject
42+
* @var NodeTypeConstraintFactory
43+
*/
44+
protected $nodeTypeConstraintFactory;
45+
46+
final protected function getEditableProperty(TraversableNodeInterface $node, string $propertyName): string
47+
{
48+
return $this->contentElementEditableService->wrapContentProperty(
49+
$node,
50+
$propertyName,
51+
$node->getProperty($propertyName) ?: ''
52+
);
53+
}
54+
55+
final protected function findChildNodesByNodeTypeFilterString(TraversableNodeInterface $parentNode, string $nodeTypeFilterString): TraversableNodes
56+
{
57+
return $parentNode->findChildNodes($this->nodeTypeConstraintFactory->parseFilterString($nodeTypeFilterString));
58+
}
59+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace PackageFactory\AtomicFusion\PresentationObjects\Fusion;
4+
5+
/*
6+
* This file is part of the PackageFactory.AtomicFusion.PresentationObjects package
7+
*/
8+
9+
/**
10+
* The interface for component presentation object factories
11+
*/
12+
interface ComponentPresentationObjectFactoryInterface
13+
{
14+
}

Classes/Fusion/ComponentPresentationObjectInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
/**
10-
* The generic interface for component presentation objects
10+
* The interface for component presentation objects
1111
*/
1212
interface ComponentPresentationObjectInterface
1313
{
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
namespace PackageFactory\AtomicFusion\PresentationObjects\Infrastructure;
3+
4+
/*
5+
* This file is part of the PackageFactory.AtomicFusion.PresentationObjects package.
6+
*/
7+
8+
use Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface;
9+
use Neos\ContentRepository\Domain\Service\Context as ContentContext;
10+
use Neos\Flow\Annotations as Flow;
11+
use Neos\Flow\Mvc\Controller\ControllerContext;
12+
use Neos\Flow\ResourceManagement\ResourceManager;
13+
use Neos\Flow\Http;
14+
use Neos\Media\Domain\Model\Asset;
15+
use Neos\Media\Domain\Model\AssetInterface;
16+
use Neos\Media\Domain\Repository\AssetRepository;
17+
use Neos\Neos\Service\LinkingService;
18+
use Neos\Flow\Mvc;
19+
use Neos\Flow\Core\Bootstrap;
20+
21+
/**
22+
* The URI service
23+
*/
24+
final class UriService
25+
{
26+
/**
27+
* @Flow\Inject
28+
* @var ResourceManager
29+
*/
30+
protected $resourceManager;
31+
32+
/**
33+
* @Flow\Inject
34+
* @var LinkingService
35+
*/
36+
protected $linkingService;
37+
38+
/**
39+
* @Flow\Inject
40+
* @var AssetRepository
41+
*/
42+
protected $assetRepository;
43+
44+
/**
45+
* @Flow\Inject
46+
* @var Bootstrap
47+
*/
48+
protected $bootstrap;
49+
50+
/**
51+
* @var ControllerContext
52+
*/
53+
protected $controllerContext;
54+
55+
/**
56+
* @param TraversableNodeInterface $documentNode
57+
* @param bool $absolute
58+
* @return string
59+
* @throws Mvc\Routing\Exception\MissingActionNameException
60+
* @throws \Neos\Flow\Property\Exception
61+
* @throws \Neos\Flow\Security\Exception
62+
* @throws \Neos\Neos\Exception
63+
*/
64+
public function getNodeUri(TraversableNodeInterface $documentNode, bool $absolute = false): string
65+
{
66+
return $this->linkingService->createNodeUri($this->getControllerContext(), $documentNode, null, null, $absolute);
67+
}
68+
69+
public function getResourceUri(string $packageKey, string $resourcePath): string
70+
{
71+
return $this->resourceManager->getPublicPackageResourceUri($packageKey, $resourcePath);
72+
}
73+
74+
public function getAssetUri(AssetInterface $asset): string
75+
{
76+
return $this->resourceManager->getPublicPersistentResourceUri($asset->getResource());
77+
}
78+
79+
public function getDummyImageBaseUri(): string
80+
{
81+
$uriBuilder = $this->getControllerContext()->getUriBuilder();
82+
83+
return $uriBuilder->uriFor(
84+
'image',
85+
[],
86+
'dummyImage',
87+
'Sitegeist.Kaleidoscope'
88+
);
89+
}
90+
91+
protected function getControllerContext(): ControllerContext
92+
{
93+
if (is_null($this->controllerContext)) {
94+
$requestHandler = $this->bootstrap->getActiveRequestHandler();
95+
if ($requestHandler instanceof Http\RequestHandler) {
96+
$request = $requestHandler->getHttpRequest();
97+
$response = $requestHandler->getHttpResponse();
98+
} else {
99+
$request = Http\Request::createFromEnvironment();
100+
$response = new Http\Response();
101+
}
102+
$actionRequest = new Mvc\ActionRequest($request);
103+
$uriBuilder = new Mvc\Routing\UriBuilder();
104+
$uriBuilder->setRequest($actionRequest);
105+
$this->controllerContext = new Mvc\Controller\ControllerContext(
106+
$actionRequest,
107+
$response,
108+
new Mvc\Controller\Arguments(),
109+
$uriBuilder
110+
);
111+
}
112+
113+
return $this->controllerContext;
114+
}
115+
116+
/**
117+
* @param string $rawLinkUri
118+
* @param ContentContext $subgraph
119+
* @return string
120+
* @throws \Neos\Flow\Mvc\Routing\Exception\MissingActionNameException
121+
* @throws \Neos\Flow\Property\Exception
122+
* @throws \Neos\Flow\Security\Exception
123+
* @throws \Neos\Neos\Exception
124+
*/
125+
public function resolveLinkUri(string $rawLinkUri, ContentContext $subgraph): string
126+
{
127+
if (\mb_substr($rawLinkUri, 0, 7) === 'node://') {
128+
$nodeIdentifier = \mb_substr($rawLinkUri, 7);
129+
$node = $subgraph->getNodeByIdentifier($nodeIdentifier);
130+
$linkUri = $node ? $this->getNodeUri($node) : '#';
131+
} elseif (\mb_substr($rawLinkUri, 0, 8) === 'asset://') {
132+
$assetIdentifier = \mb_substr($rawLinkUri, 8);
133+
/** @var Asset $asset */
134+
$asset = $this->assetRepository->findByIdentifier($assetIdentifier);
135+
$linkUri = $this->getAssetUri($asset);
136+
} elseif (\mb_substr($rawLinkUri, 0, 8) === 'https://' || \mb_substr($rawLinkUri, 0, 7) === 'http://') {
137+
$linkUri = $rawLinkUri;
138+
} else {
139+
$linkUri = '#';
140+
}
141+
142+
return $linkUri;
143+
}
144+
}

0 commit comments

Comments
 (0)