Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Commit

Permalink
✨ added AUTOID Page/File method (in caps) that ensures object is in i…
Browse files Browse the repository at this point in the history
…ndex

Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Mar 18, 2020
1 parent ea33c92 commit 4f338cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"name": "bnomei/kirby3-autoid",
"type": "kirby-plugin",
"version": "2.4.1",
"version": "2.4.2",
"description": "Automatic unique ID for Pages, Files and nested Structures including performant helpers to retrieve them. Bonus: Tiny-URL.",
"license": "MIT",
"authors": [
Expand Down
14 changes: 6 additions & 8 deletions index.php
Expand Up @@ -65,23 +65,21 @@ function searchForTemplate(string $template, string $rootId = ''): \Kirby\Cms\Co
],
'fileMethods' => [ // FILE
'AUTOID' => function () { // casesensitive
if ($this->autoid()->isEmpty()) {
$db = \Bnomei\AutoIDDatabase::singleton();
if (! $db->exists($this->autoid())) {
\Bnomei\AutoID::push($this);
return \Bnomei\AutoIDDatabase::singleton()->findByID($this->id())->autoid();
return $db->findByID($this->id())->autoid();
}
/** @var \Kirby\Cms\Page $this */

return $this->autoid()->value();
},
],
'pageMethods' => [ // PAGE
'AUTOID' => function () { // casesensitive
if ($this->autoid()->isEmpty()) {
$db = \Bnomei\AutoIDDatabase::singleton();
if (! $db->exists($this->autoid())) {
\Bnomei\AutoID::push($this);
return \Bnomei\AutoIDDatabase::singleton()->findByID($this->id())->autoid();
return $db->findByID($this->id())->autoid();
}
/** @var \Kirby\Cms\Page $this */

return $this->autoid()->value();
},
'tinyurl' => function (): string {
Expand Down

0 comments on commit 4f338cc

Please sign in to comment.