Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions Classes/Service/UsageDetailsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
use Neos\ContentRepository\Domain\Model\Node;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
use Neos\ContentRepository\Exception\NodeConfigurationException;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Exception as FlowException;
use Neos\Flow\Http\Exception as HttpException;
use Neos\Flow\Http\HttpRequestHandlerInterface;
use Neos\Flow\I18n\Exception\IndexOutOfBoundsException;
use Neos\Flow\I18n\Exception\InvalidFormatPlaceholderException;
use Neos\Flow\I18n\Translator;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Routing\Exception\MissingActionNameException;
Expand Down Expand Up @@ -66,6 +69,9 @@ final class UsageDetailsService
#[Flow\InjectConfiguration('contentDimensions', 'Neos.ContentRepository')]
protected array $contentDimensionsConfiguration = [];

#[Flow\Inject]
protected ContextFactoryInterface $contextFactory;

private array $accessibleWorkspaces = [];

public function __construct(
Expand Down Expand Up @@ -228,7 +234,9 @@ protected function resolveDimensionValuesForNode(NodeInterface $node): array
{
$dimensionValues = [];
foreach ($node->getDimensions() as $dimensionName => $dimensionValuesForName) {
$dimensionValues[$this->contentDimensionsConfiguration[$dimensionName]['label'] ?? $dimensionName] = array_map(function (
$dimensionLabel = $this->translateById(
$this->contentDimensionsConfiguration[$dimensionName]['label'] ?? $dimensionName);
$dimensionValues[$dimensionLabel] = array_map(function (
$dimensionValue
) use ($dimensionName) {
return $this->contentDimensionsConfiguration[$dimensionName]['presets'][$dimensionValue]['label'] ?? $dimensionValue;
Expand Down Expand Up @@ -300,12 +308,20 @@ protected function buildNodeUri(?Site $site, NodeInterface $node): string
$serverRequest = $serverRequest->withUri(new Uri((string)$domain));
}

$request = ActionRequest::fromHttpRequest($serverRequest);//$this->getActionRequestForUriBuilder($domain ? $domain->getHostname() : null);
// Instead of the live workspace uri we want to link to the user workspace for editing
if ($node->getWorkspace()->getBaseWorkspace() === null) {
$userWorkspaceContextProperties = [
'workspaceName' => $this->userService->getPersonalWorkspaceName(),
];
$userWorkspaceContext = $this->contextFactory->create(array_merge($node->getContext()->getProperties(), $userWorkspaceContextProperties));
$node = $userWorkspaceContext->getNodeByIdentifier($node->getIdentifier());
}

$request = ActionRequest::fromHttpRequest($serverRequest);

$uriBuilder = new UriBuilder();
$uriBuilder->setRequest($request);
$uriBuilder->setCreateAbsoluteUri(false);

$requestUri = $serverRequest->getUri();
$relativeNodeBackendUri = $uriBuilder->uriFor(
'index',
Expand Down Expand Up @@ -421,9 +437,28 @@ public function getUnusedAssetCount(): int
->getSingleScalarResult();
}

/**
* @throws InvalidFormatPlaceholderException
* @throws IndexOutOfBoundsException
*/
protected function translateById(string $id): ?string
{
return $this->translator->translateById($id, [], null, null, 'Main', 'Flowpack.Media.Ui') ?? $id;
$source = 'Main';
$package = 'Flowpack.Media.Ui';

$shortHandStringParts = explode(':', $id);
if (count($shortHandStringParts) === 3) {
[$package, $source, $id] = $shortHandStringParts;
}

return $this->translator->translateById(
$id,
[],
null,
null,
$source,
$package,
) ?? $id;
}

/**
Expand Down
Loading