Skip to content

Commit a5df5a4

Browse files
authored
Merge pull request #9 from visuellverstehen/8-add-possibility-to-get-content-from-other-entry
feat: add possibilty to get headings from entry
2 parents 7c35b0d + b4750f1 commit a5df5a4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Tags/AnchorNavigation.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace VV\AnchorNavigation\Tags;
44

5+
use Statamic\Entries\Entry;
56
use Statamic\Facades\Config;
67
use Statamic\Fieldtypes\Bard\Augmentor;
78
use Statamic\Tags\Tags;
@@ -19,15 +20,15 @@ class AnchorNavigation extends Tags
1920
* In order to generate an anchor navigation
2021
* you need to provide the field handle for a bard field.
2122
*
22-
* {{ anchor_navigation from="handle" }}
23+
* {{ anchor_navigation from="handle" entry="entry" }}
2324
*/
2425
public function index(): ?array
2526
{
2627
if (! $this->fieldHandle = $this->params->get('from')) {
2728
return null;
2829
}
2930

30-
if (! $this->entry = $this->context->get('id')?->augmentable()) {
31+
if (! $this->entry = $this->getEntry()) {
3132
return null;
3233
}
3334

@@ -107,4 +108,16 @@ protected function sanitize($string): string
107108
{
108109
return htmlspecialchars($string, ENT_QUOTES, Config::get('statamic.system.charset', 'UTF-8'));
109110
}
111+
112+
113+
/**
114+
* This method makes it possible to create an Anchor navigation not only
115+
* from the current context, but also by passing another entry.
116+
*/
117+
private function getEntry(): ?Entry
118+
{
119+
return $this->params->get('entry')
120+
? $this->params->get('entry')
121+
: $this->context->get('id')?->augmentable();
122+
}
110123
}

0 commit comments

Comments
 (0)