Skip to content

Commit

Permalink
Merge pull request #5278 from mhsdesign/bugfix/90-ce-wrapping-enforce…
Browse files Browse the repository at this point in the history
…-dom-node-for-augmentation

BUGFIX: Prevent augmenter from applying data of multiple nodes into the same element
  • Loading branch information
mhsdesign authored Oct 9, 2024
2 parents f7bcf22 + 3e48aba commit eeeb3f0
Showing 1 changed file with 9 additions and 36 deletions.
45 changes: 9 additions & 36 deletions Neos.Neos/Classes/Service/ContentElementWrappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Authorization\PrivilegeManagerInterface;
use Neos\Flow\Session\SessionInterface;
use Neos\Fusion\Service\HtmlAugmenter as FusionHtmlAugmenter;
use Neos\Neos\FrontendRouting\NodeAddressFactory;

Expand All @@ -31,24 +29,12 @@
*/
class ContentElementWrappingService
{
/**
* @Flow\Inject
* @var PrivilegeManagerInterface
*/
protected $privilegeManager;

/**
* @Flow\Inject
* @var FusionHtmlAugmenter
*/
protected $htmlAugmenter;

/**
* @Flow\Inject
* @var SessionInterface
*/
protected $session;

/**
* @Flow\Inject
* @var ContentRepositoryRegistry
Expand Down Expand Up @@ -81,27 +67,14 @@ public function wrapContentObject(
$attributes['data-__neos-fusion-path'] = $fusionPath;
$attributes['data-__neos-node-contextpath'] = $nodeAddress->serializeForUri();

return $this->htmlAugmenter->addAttributes($content, $attributes, 'div');
}

/**
* Add required CSS classes to the attributes.
*
* @param array<string,mixed> $attributes
* @param array<string,mixed> $initialClasses
* @return array<string,mixed>
*/
protected function addCssClasses(array $attributes, Node $node, array $initialClasses = []): array
{
$classNames = $initialClasses;
if (!$node->dimensionSpacePoint->equals($node->originDimensionSpacePoint)) {
$classNames[] = 'neos-contentelement-shine-through';
}

if ($classNames !== []) {
$attributes['class'] = implode(' ', $classNames);
}

return $attributes;
// Define all attribute names as exclusive via the `exclusiveAttributes` parameter, to prevent the data of
// two different nodes to be concatenated into the attributes of a single html node.
// This way an outer div is added, if the wrapped content already has node related data-attributes set.
return $this->htmlAugmenter->addAttributes(
$content,
$attributes,
'div',
array_keys($attributes)
);
}
}

0 comments on commit eeeb3f0

Please sign in to comment.