Skip to content

Commit 979ccbd

Browse files
authored
[BUGFIX] Improve typo3 file directive (#903)
1 parent 16fd935 commit 979ccbd

File tree

7 files changed

+44
-33
lines changed

7 files changed

+44
-33
lines changed

packages/typo3-docs-theme/resources/template/body/directive/typo3-file.html.twig

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<section data-search-title="{{ node.path }}{{ node.plainContent }}"
1+
<section data-search-title="{{ node.composerPath }}{{ node.plainContent }}"
22
data-search-id="{{ node.anchor }}"
33
data-search-facet="file"
44
class="confval-section"
55
>
6-
<h3 class="sr-only">{{ node.path }}{{ node.plainContent }}</h3>
6+
<h3 class="sr-only">{{ node.composerPath }}{{ node.plainContent }}</h3>
77
<dl class="confval">
88
<dt{% if not node.noindex %} id="{{ node.anchor }}"{% endif %}
99
class="d-flex justify-content-between">
@@ -31,17 +31,13 @@
3131
<dt class="field-even">Scope</dt>
3232
<dd class="field-even">{{ node.scope }}</dd>
3333
{% endif -%}
34-
{% if node.path %}
35-
<dt class="field-even">Path</dt>
36-
<dd class="field-even">{{ node.path }}{{ node.plainContent }}</dd>
37-
{% endif -%}
3834
{% if node.composerPathPrefix or node.composerPath %}
3935
<dt class="field-even">Path (Composer)</dt>
40-
<dd class="field-even">{{ node.composerPathPrefix }}{{ node.composerPath }}{{ node.path }}{{ node.plainContent }}</dd>
36+
<dd class="field-even">{{ node.composerPathPrefix }}{{ node.composerPath }}{{ node.plainContent }}</dd>
4137
{% endif -%}
4238
{%- if node.classicPathPrefix or node.classicPath %}
4339
<dt class="field-odd">Path (Classic)</dt>
44-
<dd class="field-odd">{{ node.classicPathPrefix }}{{ node.classicPath }}{{ node.path }}{{ node.plainContent }}</dd>
40+
<dd class="field-odd">{{ node.classicPathPrefix }}{{ node.classicPath }}{{ node.plainContent }}</dd>
4541
{% endif -%}
4642
{% if node.configuration %}
4743
<dt class="field-odd">Configuration</dt>

packages/typo3-docs-theme/src/Compiler/NodeTransformers/AttachFileObjectsToFileTextRoleTransformer.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ public function enterNode(Node $node, CompilerContextInterface $compilerContext)
3535
}
3636
/** @var DataObject[] $fileObjects */
3737
$fileObjects = $this->objectInventory->getGroup(FileObject::KEY);
38+
foreach ($fileObjects as $fileObject) {
39+
if (!$fileObject instanceof FileObject) {
40+
continue;
41+
}
42+
if ($fileObject->id === $node->getFileLink()) {
43+
$node->setFileObject($fileObject);
44+
return $node;
45+
}
46+
if (preg_match($fileObject->regex, $node->getFileLink())) {
47+
$node->setFileObject($fileObject);
48+
break;
49+
}
50+
}
3851
foreach ($fileObjects as $fileObject) {
3952
if (!$fileObject instanceof FileObject) {
4053
continue;

packages/typo3-docs-theme/src/Directives/Typo3FileDirective.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ protected function processSub(
8282
id: $key,
8383
fileName: $filename,
8484
language: $language,
85-
path: $this->getPath($path),
86-
composerPath: $this->getPath($directive->getOptionString('composerPath')),
85+
composerPath: $directive->hasOption('composerPath') ? $this->getPath($directive->getOptionString('composerPath')) : $this->getPath($path),
8786
composerPathPrefix: $this->getPath($pathPrefix),
88-
classicPath: $this->getPath($directive->getOptionString('classicPath')),
87+
classicPath: $directive->hasOption('classicPath') ? $this->getPath($directive->getOptionString('classicPath')) : $this->getPath($path),
8988
classicPathPrefix: $this->getPath($classicPathPrefix),
9089
scope: $directive->getOptionString('scope'),
9190
regex: $regex,

packages/typo3-docs-theme/src/Nodes/Typo3FileNode.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public function __construct(
2222
private readonly string $id,
2323
private readonly string $fileName,
2424
private readonly string $language,
25-
private readonly string $path,
2625
private readonly string $composerPath = '',
2726
private readonly string $composerPathPrefix = '',
2827
private readonly string $classicPath = '',
@@ -53,11 +52,6 @@ public function getLanguage(): string
5352
return $this->language;
5453
}
5554

56-
public function getPath(): string
57-
{
58-
return $this->path;
59-
}
60-
6155
public function getClassicPath(): string
6256
{
6357
return $this->classicPath;

packages/typo3-docs-theme/src/ReferenceResolvers/ObjectsInventory/FileObject.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class FileObject implements DataObject
1010
public function __construct(
1111
public string $fileName,
1212
public string $language,
13-
public string $path,
1413
public string $composerPath = '',
1514
public string $composerPathPrefix = '',
1615
public string $classicPath = '',
@@ -26,7 +25,6 @@ public static function fromTypo3Node(Typo3FileNode $node): FileObject
2625
return new FileObject(
2726
$node->getFileName(),
2827
$node->getLanguage(),
29-
$node->getPath(),
3028
$node->getComposerPath(),
3129
$node->getComposerPathPrefix(),
3230
$node->getClassicPath(),

tests/Integration/tests/typo3-file/expected/index.html

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h3 class="sr-only">Configuration/page.tsconfig</h3>
5454
data-bs-toggle="modal"
5555
data-bs-target="#linkReferenceModal"
5656
data-id="file-extension-configuration-page-tsconfig"
57-
data-rstCode=":file:`packages/my_extension/page.tsconfig`"
57+
data-rstCode=":file:`packages/my_extension/Configuration/page.tsconfig`"
5858
title="Reference this file definition"><i
5959
class="fa-solid fa-paragraph"></i></a>
6060
</div>
@@ -63,8 +63,6 @@ <h3 class="sr-only">Configuration/page.tsconfig</h3>
6363
<dl class="field-list simple">
6464
<dt class="field-even">Scope</dt>
6565
<dd class="field-even">extension</dd>
66-
<dt class="field-even">Path</dt>
67-
<dd class="field-even">Configuration/page.tsconfig</dd>
6866
<dt class="field-even">Path (Composer)</dt>
6967
<dd class="field-even">packages/my_extension/Configuration/page.tsconfig</dd>
7068
<dt class="field-odd">Path (Classic)</dt>
@@ -79,12 +77,12 @@ <h3 class="sr-only">Configuration/page.tsconfig</h3>
7977
</dd>
8078
</dl>
8179
</section>
82-
<section data-search-title="settings.php"
80+
<section data-search-title="config/system/settings.php"
8381
data-search-id="file-project-config-system-settings-php"
8482
data-search-facet="file"
8583
class="confval-section"
8684
>
87-
<h3 class="sr-only">settings.php</h3>
85+
<h3 class="sr-only">config/system/settings.php</h3>
8886
<dl class="confval">
8987
<dt id="file-project-config-system-settings-php" class="d-flex justify-content-between">
9088
<div class="confval-header">
@@ -117,12 +115,12 @@ <h3 class="sr-only">settings.php</h3>
117115
</dd>
118116
</dl>
119117
</section>
120-
<section data-search-title="ENABLE_INSTALL_TOOL"
118+
<section data-search-title="config/ENABLE_INSTALL_TOOL"
121119
data-search-id="file-project-config-enable-install-tool"
122120
data-search-facet="file"
123121
class="confval-section"
124122
>
125-
<h3 class="sr-only">ENABLE_INSTALL_TOOL</h3>
123+
<h3 class="sr-only">config/ENABLE_INSTALL_TOOL</h3>
126124
<dl class="confval">
127125
<dt id="file-project-config-enable-install-tool" class="d-flex justify-content-between">
128126
<div class="confval-header">
@@ -154,12 +152,12 @@ <h3 class="sr-only">ENABLE_INSTALL_TOOL</h3>
154152
</dd>
155153
</dl>
156154
</section>
157-
<section data-search-title="LOCK_BACKEND"
155+
<section data-search-title="var/lock/LOCK_BACKEND"
158156
data-search-id="file-project-var-lock-lock-backend"
159157
data-search-facet="file"
160158
class="confval-section"
161159
>
162-
<h3 class="sr-only">LOCK_BACKEND</h3>
160+
<h3 class="sr-only">var/lock/LOCK_BACKEND</h3>
163161
<dl class="confval">
164162
<dt id="file-project-var-lock-lock-backend" class="d-flex justify-content-between">
165163
<div class="confval-header">
@@ -238,12 +236,12 @@ <h3 class="sr-only">config.yaml</h3>
238236
</dd>
239237
</dl>
240238
</section>
241-
<section data-search-title="SomeClass.php"
239+
<section data-search-title="Classes/SomeClass.php"
242240
data-search-id="file-extension-classes-someclass-php"
243241
data-search-facet="file"
244242
class="confval-section"
245243
>
246-
<h3 class="sr-only">SomeClass.php</h3>
244+
<h3 class="sr-only">Classes/SomeClass.php</h3>
247245
<dl class="confval">
248246
<dt id="file-extension-classes-someclass-php" class="d-flex justify-content-between">
249247
<div class="confval-header">
@@ -368,6 +366,19 @@ <h2>Linking files<a class="headerlink" href="#linking-files" data-bs-toggle="mod
368366
><code class="code-inline file" translate="no">Configuration File</code><i class="fa-regular fa-circle-question"></i></a></li>
369367
<li><code class="code-inline file" translate="no" title="File path">Unknown/<wbr>File.<wbr>xyz</code></li>
370368
<li><code class="code-inline file" translate="no" title="File path">FILE:<wbr>EXT:<wbr>Unknown/<wbr>File.<wbr>xyz</code></li>
369+
<li><a class="composer-link"
370+
href="#file-extension-classes-someclass-php"
371+
title="File Information"
372+
data-bs-toggle="modal"
373+
data-bs-target="#generalModal"
374+
data-filename="SomeClass.php"
375+
data-scope="extension"
376+
data-classicpath="Classes/"
377+
data-composerpath="Classes/"
378+
data-classicpathprefix="typo3conf/ext/my_extension/"
379+
data-composerpathprefix="packages/my_extension/"
380+
data-shortdescription="PHP Classes in this file get auto-loaded"
381+
><code class="code-inline file" translate="no">SomeClass.php</code><i class="fa-regular fa-circle-question"></i></a></li>
371382
</ul>
372383

373384
</section>

tests/Integration/tests/typo3-file/input/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ TYPO3 Files
5454
:regex: /.*Configuration\/Sets\/[^\/]+\/config\.yaml$/
5555

5656
.. typo3:file:: SomeClass.php
57-
:path: /
57+
:name: classes-someclass-php
5858
:scope: extension
59-
:composerPath: /Classes/
60-
:classicPath: /Classes/
59+
:path: /Classes/
6160
:regex: /^.*Classes\/.*\.php/
6261
:shortDescription: PHP Classes in this file get auto-loaded
6362

@@ -73,6 +72,7 @@ Linking files
7372
* :file:`Configuration File <Configuration/Sets/MySet/config.yaml>`
7473
* :file:`Unknown/File.xyz`
7574
* :file:`FILE:EXT:Unknown/File.xyz`
75+
* :file:`SomeClass.php <extension-classes-someclass-php>`
7676

7777
Code Block captions
7878
===================

0 commit comments

Comments
 (0)