xref: /plugin/dw2pdf/src/BookCreatorSavedSelectionCollector.php (revision 5340eaffbcc1177667ac835e4e719d9eb8959315)
1<?php
2
3namespace dokuwiki\plugin\dw2pdf\src;
4
5class BookCreatorSavedSelectionCollector extends AbstractCollector
6{
7    /**
8     * @inheritdoc
9     * @throws \JsonException
10     */
11    protected function collect(): array
12    {
13        /** @var action_plugin_bookcreator_handleselection $bcPlugin */
14        $bcPlugin = plugin_load('action', 'bookcreator_handleselection');
15        if (!$bcPlugin) return [];
16
17        $savedSelectionId = $this->getConfig()->getSavedSelection();
18        if ($savedSelectionId === null) return [];
19
20        $savedselection = $bcPlugin->loadSavedSelection($savedSelectionId);
21        if (!$this->title && !empty($savedselection['title'])) {
22            $this->title = $savedselection['title'];
23        }
24
25        $list = (array) $savedselection['selection'];
26        return array_filter($list, fn($page) => page_exists($page));
27    }
28}
29