forked from TYPO3-Documentation/render-guides
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveInterlinkSelfReferencesFromCrossReferenceNodeTransformer.php
More file actions
78 lines (68 loc) · 2.32 KB
/
RemoveInterlinkSelfReferencesFromCrossReferenceNodeTransformer.php
File metadata and controls
78 lines (68 loc) · 2.32 KB
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
76
77
78
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link https://phpdoc.org
*/
namespace T3Docs\Typo3DocsTheme\Compiler\NodeTransformers;
use phpDocumentor\Guides\Compiler\CompilerContextInterface;
use phpDocumentor\Guides\Compiler\NodeTransformer;
use phpDocumentor\Guides\Nodes\Inline\CrossReferenceNode;
use phpDocumentor\Guides\Nodes\Inline\DocReferenceNode;
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
use phpDocumentor\Guides\Nodes\Node;
use T3Docs\Typo3DocsTheme\Settings\Typo3DocsThemeSettings;
use function assert;
/** @implements NodeTransformer<CrossReferenceNode> */
final class RemoveInterlinkSelfReferencesFromCrossReferenceNodeTransformer implements NodeTransformer
{
public function __construct(
private readonly Typo3DocsThemeSettings $themeSettings,
) {}
public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node
{
return $node;
}
public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node
{
assert($node instanceof CrossReferenceNode);
if (!$this->themeSettings->hasSettings('interlink_shortcode')) {
return $node;
}
$interlink = $this->themeSettings->getSettings('interlink_shortcode');
if ($interlink === '' || $node->getInterlinkDomain() !== $interlink) {
return $node;
}
// Remove interlink references to the own current document
if ($node instanceof ReferenceNode) {
$newRef = new ReferenceNode(
$node->getTargetReference(),
$node->getChildren(),
'',
$node->getLinkType(),
$node->getPrefix()
);
return $newRef;
}
if ($node instanceof DocReferenceNode) {
$newDocRef = new DocReferenceNode(
$node->getTargetReference(),
$node->getChildren(),
);
return $newDocRef;
}
return $node;
}
public function supports(Node $node): bool
{
return $node instanceof CrossReferenceNode;
}
public function getPriority(): int
{
return 1000;
}
}