Skip to content

Commit 1c09d5a

Browse files
committed
Tiny tweaks to ContentService
1 parent a7ba4dd commit 1c09d5a

File tree

1 file changed

+4
-45
lines changed

1 file changed

+4
-45
lines changed

Classes/Service/ContentService.php

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function renderTeaser(NodeInterface $node, int $maximumLength = 500): str
5050
foreach ($contentNodes as $contentNode) {
5151
foreach ($contentNode->getProperties() as $propertyValue) {
5252
if (!is_object($propertyValue) || method_exists($propertyValue, '__toString')) {
53-
$stringToTruncate .= $propertyValue;
53+
$stringToTruncate .= $propertyValue . PHP_EOL;
5454
}
5555
}
5656
}
@@ -67,7 +67,7 @@ public function renderTeaser(NodeInterface $node, int $maximumLength = 500): str
6767

6868
// If we found a suitable paragraph break, use it
6969
$bestEndPosition = max($validPositions);
70-
if ($bestEndPosition !== null) {
70+
if ($bestEndPosition > 0) {
7171
return $this->stripUnwantedTags(substr($stringToTruncate, 0, $bestEndPosition));
7272
}
7373

@@ -82,9 +82,9 @@ public function renderTeaser(NodeInterface $node, int $maximumLength = 500): str
8282
* Find all positions of '</p>' in the given HTML string.
8383
*
8484
* @param string $html
85-
* @return array
85+
* @return int[]
8686
*/
87-
protected function getPTagPositions(string $html) {
87+
protected function getPTagPositions(string $html): array {
8888
$positions = [];
8989
$offset = 0;
9090

@@ -96,47 +96,6 @@ protected function getPTagPositions(string $html) {
9696
return $positions;
9797
}
9898

99-
/**
100-
* @param NodeInterface $node
101-
* @return string
102-
* @throws NodeException
103-
*/
104-
public function renderContent(NodeInterface $node): string
105-
{
106-
$content = '';
107-
$childNodes = $this->getContentNodesFromMainCollection($node);
108-
109-
/** @var NodeInterface $contentNode */
110-
foreach ($childNodes as $contentNode) {
111-
if ($contentNode->getNodeType()->isOfType('Neos.NodeTypes:TextWithImage')) {
112-
$propertyValue = $contentNode->getProperty('image');
113-
$attributes = [
114-
'width="' . $propertyValue->getWidth() . '"',
115-
'height="' . $propertyValue->getHeight() . '"',
116-
'src="' . $this->resourceManager->getPublicPersistentResourceUri($propertyValue->getResource()) . '"'
117-
];
118-
$content .= $contentNode->getProperty('text');
119-
$content .= '<img ' . implode(' ', $attributes) . '/>';
120-
} elseif ($contentNode->getNodeType()->isOfType('Neos.NodeTypes:Image')) {
121-
$propertyValue = $contentNode->getProperty('image');
122-
$attributes = [
123-
'width="' . $propertyValue->getWidth() . '"',
124-
'height="' . $propertyValue->getHeight() . '"',
125-
'src="' . $this->resourceManager->getPublicPersistentResourceUri($propertyValue->getResource()) . '"'
126-
];
127-
$content .= '<img ' . implode(' ', $attributes) . '/>';
128-
} else {
129-
foreach ($contentNode->getProperties() as $propertyValue) {
130-
if (!is_object($propertyValue) || method_exists($propertyValue, '__toString')) {
131-
$content .= $propertyValue;
132-
}
133-
}
134-
}
135-
}
136-
137-
return $this->stripUnwantedTags($content);
138-
}
139-
14099
/**
141100
* @param NodeInterface $node
142101
* @return TraversableNodes

0 commit comments

Comments
 (0)