Skip to content

Commit ac2c1ab

Browse files
author
Bernhard Schmitt
committed
Introduce self-wrapping capabilities for presentational components
1 parent ae84fa3 commit ac2c1ab

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

Classes/Fusion/AbstractComponentPresentationObjectFactory.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Neos\Flow\Annotations as Flow;
1414
use Neos\Flow\I18n\Translator;
1515
use Neos\Neos\Service\ContentElementEditableService;
16+
use Neos\Neos\Service\ContentElementWrappingService;
1617
use PackageFactory\AtomicFusion\PresentationObjects\Infrastructure\UriService;
1718

1819
/**
@@ -38,12 +39,27 @@ abstract class AbstractComponentPresentationObjectFactory implements ComponentPr
3839
*/
3940
protected $contentElementEditableService;
4041

42+
/**
43+
* @Flow\Inject
44+
* @var ContentElementWrappingService
45+
*/
46+
protected $contentElementWrappingService;
47+
4148
/**
4249
* @Flow\Inject
4350
* @var NodeTypeConstraintFactory
4451
*/
4552
protected $nodeTypeConstraintFactory;
4653

54+
final protected function createWrapper(TraversableNodeInterface $node, PresentationObjectComponentImplementation $fusionObject): callable
55+
{
56+
$wrappingService = $this->contentElementWrappingService;
57+
58+
return function(string $content) use($node, $fusionObject, $wrappingService) {
59+
return $wrappingService->wrapContentObject($node, $content, $fusionObject->getPath());
60+
};
61+
}
62+
4763
final protected function getEditableProperty(TraversableNodeInterface $node, string $propertyName): string
4864
{
4965
return $this->contentElementEditableService->wrapContentProperty(
@@ -60,6 +76,7 @@ final protected function findChildNodesByNodeTypeFilterString(TraversableNodeInt
6076

6177
/**
6278
* All methods are considered safe
79+
*
6380
* @param string $methodName
6481
* @return boolean
6582
*/

Classes/Fusion/PresentationObjectComponentImplementation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ protected function prepare($context)
3939
return parent::prepare($context);
4040
}
4141

42+
public function getPath(): string
43+
{
44+
return $this->path;
45+
}
46+
4247
protected function isInPreviewMode(): bool
4348
{
4449
return $this->fusionValue(self::PREVIEW_MODE);

Classes/Fusion/SelfWrapping.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 trait for self-wrapping presentation components for inline editing
11+
*
12+
* The wrapper function should be created by AbstractComponentPresentationObjectFactory::createWrapper()
13+
*/
14+
trait SelfWrapping
15+
{
16+
/**
17+
* @var callable|null
18+
*/
19+
private $wrapper;
20+
21+
final public function wrap(string $value): string
22+
{
23+
$wrapper = $this->wrapper;
24+
25+
return $wrapper ? $wrapper($value) : $value;
26+
}
27+
}

0 commit comments

Comments
 (0)