This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from johannschopplich/chore/readme-update
chore: raise Kirby's composer installer version refactor: remove unused namespaces refactor: re-use more pages logic from parent feat: add flip option chore: improve readme and fix some typos Thx @johannschopplich
- Loading branch information
Showing
5 changed files
with
90 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
panel.plugin('rasteiner/k3-pagesdisplay-section', { | ||
panel.plugin("rasteiner/k3-pagesdisplay-section", { | ||
components: { | ||
'k-pagesdisplay-section': { | ||
extends: 'k-pages-section' | ||
} | ||
} | ||
"k-pagesdisplay-section": { | ||
extends: "k-pages-section", | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
<?php | ||
|
||
use Kirby\Cms\App; | ||
use Kirby\Cms\Blueprint; | ||
use Kirby\Toolkit\F; | ||
use Kirby\Toolkit\Str; | ||
|
||
Kirby::plugin('rasteiner/k3-pagesdisplay-section', [ | ||
\Kirby\Cms\App::plugin('rasteiner/k3-pagesdisplay-section', [ | ||
'sections' => [ | ||
'pagesdisplay' => require __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'PagesDisplaySection.php' | ||
'pagesdisplay' => require __DIR__ . '/src/PagesDisplaySection.php' | ||
] | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,78 @@ | ||
<?php | ||
|
||
use Kirby\Exception\InvalidArgumentException; | ||
use Kirby\Toolkit\Str; | ||
use Kirby\Toolkit\Query; | ||
use Kirby\Cms\Section; | ||
use Kirby\Toolkit\Query; | ||
|
||
$base = Section::$types['pages']; | ||
|
||
return array_replace_recursive($base, [ | ||
$extension = [ | ||
'props' => [ | ||
'sortable' => function (bool $sortable = true) { | ||
return false; | ||
}, | ||
'query' => function(string $query = 'page.children') { | ||
'query' => function (string $query = 'page.children') { | ||
return $query; | ||
} | ||
], | ||
'computed' => [ | ||
'pages' => function () { | ||
'pages' => function () { | ||
$kirby = kirby(); | ||
$q = new Query($this->query, [ | ||
'site' => site(), | ||
'page' => $this->model(), | ||
'pages' => site()->pages(), | ||
'kirby' => kirby() | ||
'kirby' => $kirby, | ||
'site' => $kirby->site(), | ||
'pages' => $kirby->site()->pages(), | ||
'page' => $this->model() | ||
]); | ||
|
||
$pages = $q->result(); | ||
|
||
if(is_a($pages, 'Kirby\\Cms\\Pages')) { | ||
// show only readable | ||
$pages = $pages->filterBy("isReadable", true); | ||
|
||
// sort | ||
if ($this->sortBy) { | ||
$pages = $pages->sortBy(...Str::split($this->sortBy, ' ')); | ||
} | ||
|
||
// pagination | ||
$pages = $pages->paginate([ | ||
'page' => $this->page, | ||
'limit' => $this->limit | ||
]); | ||
|
||
return $pages; | ||
} else { | ||
if (!is_a($pages, \Kirby\Cms\Pages::class)) { | ||
$result = $pages === null ? 'null' : get_class($pages); | ||
throw new InvalidArgumentException( | ||
'Invalid query result - Result must be of type Kirby\\Cms\\Pages, ' | ||
. ($pages === NULL ? 'NULL' : get_class($pages)) | ||
. ' given.' | ||
"Query result must be of type \"Kirby\\Cms\\Pages\", \"{$result}\" given" | ||
); | ||
} | ||
|
||
// Loop for the best performance | ||
foreach ($pages->data as $id => $page) { | ||
// Remove all protected pages | ||
if (!$page->isReadable()) { | ||
unset($pages->data[$id]); | ||
continue; | ||
} | ||
|
||
// Filter by all set templates | ||
if ($this->templates && !in_array($page->intendedTemplate()->name(), $this->templates)) { | ||
unset($pages->data[$id]); | ||
continue; | ||
} | ||
} | ||
|
||
// Sort pages | ||
if ($this->sortBy) { | ||
$pages = $pages->sort(...$pages::sortArgs($this->sortBy)); | ||
} | ||
|
||
// Flip pages | ||
if ($this->flip) { | ||
$pages = $pages->flip(); | ||
} | ||
|
||
// Add pagination | ||
$pages = $pages->paginate([ | ||
'page' => $this->page, | ||
'limit' => $this->limit | ||
]); | ||
|
||
return $pages; | ||
}, | ||
'add' => function () { | ||
return false; | ||
}, | ||
'sortable' => function () { | ||
return false; | ||
} | ||
], | ||
]); | ||
] | ||
]; | ||
|
||
return array_replace_recursive($base, $extension); |