/
ContentElementEditableService.php
75 lines (66 loc) · 2.18 KB
/
ContentElementEditableService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Neos\Neos\Service;
/*
* This file is part of the Neos.Neos package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Authorization\PrivilegeManagerInterface;
use Neos\Neos\Domain\Service\ContentContext;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Service\AuthorizationService;
use Neos\Fusion\Service\HtmlAugmenter as FusionHtmlAugmenter;
/**
* The content element editable service adds the necessary markup around
* a content element such that it can be edited using the inline editing
* of the Neos Backend.
*
* @Flow\Scope("singleton")
*/
class ContentElementEditableService
{
/**
* @Flow\Inject
* @var PrivilegeManagerInterface
*/
protected $privilegeManager;
/**
* @Flow\Inject
* @var AuthorizationService
*/
protected $nodeAuthorizationService;
/**
* @Flow\Inject
* @var FusionHtmlAugmenter
*/
protected $htmlAugmenter;
/**
* Wrap the $content identified by $node with the needed markup for the backend.
*
* @param NodeInterface $node
* @param string $property
* @param string $content
* @return string
*/
public function wrapContentProperty(NodeInterface $node, $property, $content)
{
/** @var $contentContext ContentContext */
$contentContext = $node->getContext();
if ($contentContext->getWorkspaceName() === 'live' || !$this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) {
return $content;
}
if (!$this->nodeAuthorizationService->isGrantedToEditNode($node)) {
return $content;
}
$attributes = [];
$attributes['class'] = 'neos-inline-editable';
$attributes['property'] = 'typo3:' . $property ;
$attributes['data-neos-node-type'] = $node->getNodeType()->getName();
return $this->htmlAugmenter->addAttributes($content, $attributes, 'span');
}
}