Skip to content

Commit 94319a4

Browse files
[BUGFIX] Limit doktype support in page tree context menu
Resolves: #161
1 parent df966e2 commit 94319a4

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

Classes/Backend/ContextMenu/ItemProviders/CacheWarmupProvider.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace EliasHaeussler\Typo3Warming\Backend\ContextMenu\ItemProviders;
2525

26+
use EliasHaeussler\Typo3Warming\Configuration\Configuration;
2627
use EliasHaeussler\Typo3Warming\Sitemap\SitemapLocator;
2728
use EliasHaeussler\Typo3Warming\Traits\BackendUserAuthenticationTrait;
2829
use EliasHaeussler\Typo3Warming\Utility\AccessUtility;
@@ -89,11 +90,17 @@ class CacheWarmupProvider extends PageProvider
8990
*/
9091
protected $siteFinder;
9192

93+
/**
94+
* @var Configuration
95+
*/
96+
protected $configuration;
97+
9298
public function __construct(string $table, string $identifier, string $context = '')
9399
{
94100
parent::__construct($table, $identifier, $context);
95101
$this->sitemapLocator = GeneralUtility::makeInstance(SitemapLocator::class);
96102
$this->siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
103+
$this->configuration = GeneralUtility::makeInstance(Configuration::class);
97104
}
98105

99106
protected function canRender(string $itemName, string $type): bool
@@ -103,6 +110,12 @@ protected function canRender(string $itemName, string $type): bool
103110
return true;
104111
}
105112

113+
// Non-supported doktypes are never renderable
114+
$doktype = (int)($this->record['doktype'] ?? null);
115+
if ($doktype <= 0 || !\in_array($doktype, $this->configuration->getSupportedDoktypes(), true)) {
116+
return false;
117+
}
118+
106119
// Language items in sub-menus are already filtered
107120
if (str_starts_with($itemName, 'lang_')) {
108121
return true;
@@ -131,14 +144,20 @@ protected function canRender(string $itemName, string $type): bool
131144
*/
132145
public function addItems(array $items): array
133146
{
134-
$this->initDisabledItems();
135-
$this->initSubMenus();
147+
$this->initialize();
148+
136149
$localItems = $this->prepareItems($this->itemsConfiguration);
137150
$items += $localItems;
138151

139152
return $items;
140153
}
141154

155+
protected function initialize(): void
156+
{
157+
parent::initialize();
158+
$this->initSubMenus();
159+
}
160+
142161
public function getPriority(): int
143162
{
144163
return 50;

Classes/Configuration/Configuration.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
use EliasHaeussler\Typo3Warming\Crawler\ConcurrentUserAgentCrawler;
2929
use EliasHaeussler\Typo3Warming\Crawler\OutputtingUserAgentCrawler;
3030
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
31+
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
3132
use TYPO3\CMS\Core\Exception;
33+
use TYPO3\CMS\Core\Utility\GeneralUtility;
3234
use TYPO3\CMS\Extbase\Security\Cryptography\HashService;
3335

3436
/**
@@ -42,6 +44,9 @@ final class Configuration
4244
public const DEFAULT_LIMIT = 250;
4345
public const DEFAULT_CRAWLER = ConcurrentUserAgentCrawler::class;
4446
public const DEFAULT_VERBOSE_CRAWLER = OutputtingUserAgentCrawler::class;
47+
public const DEFAULT_SUPPORTED_DOKTYPES = [
48+
PageRepository::DOKTYPE_DEFAULT,
49+
];
4550

4651
/**
4752
* @var ExtensionConfiguration
@@ -154,6 +159,24 @@ public function getVerboseCrawlerOptions(): array
154159
}
155160
}
156161

162+
/**
163+
* @return list<int>
164+
*/
165+
public function getSupportedDoktypes(): array
166+
{
167+
try {
168+
$doktypes = $this->configuration->get(Extension::KEY, 'supportedDoktypes');
169+
170+
if (!\is_string($doktypes)) {
171+
return self::DEFAULT_SUPPORTED_DOKTYPES;
172+
}
173+
174+
return GeneralUtility::intExplode(',', $doktypes, true);
175+
} catch (Exception $e) {
176+
return self::DEFAULT_SUPPORTED_DOKTYPES;
177+
}
178+
}
179+
157180
public function getUserAgent(): string
158181
{
159182
return $this->userAgent;

Documentation/Configuration/ExtensionConfiguration.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,15 @@ The extension currently provides the following configuration options:
7171
:ref:`crawler <extconf-verboseCrawler>`. Applies only to crawlers implementing the
7272
:php:interface:`EliasHaeussler\\CacheWarmup\\Crawler\\ConfigurableCrawlerInterface`.
7373
For more information read :ref:`configurable-crawlers`.
74+
75+
.. _extconf-supportedDoktypes:
76+
77+
.. confval:: supportedDoktypes
78+
79+
:type: string (comma-separated list)
80+
:Default: 1
81+
82+
Comma-separated list of doktypes to be supported for cache warmup in the
83+
:ref:`page tree <page-tree>` context menu. Defaults to default pages with doktype
84+
:php:`1` only. If your project implements custom doktypes, you can add them here to
85+
support cache warmup from the context menu.

ext_conf_template.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ verboseCrawler = EliasHaeussler\Typo3Warming\Crawler\OutputtingUserAgentCrawler
1212

1313
# cat=basic/35; type=string; label=Verbose crawler options (JSON-encoded string):Provide crawler options for the verbose crawler. Applies only if the verbose crawler implements the interface "EliasHaeussler\CacheWarmup\Crawler\ConfigurableCrawlerInterface".
1414
verboseCrawlerOptions =
15+
16+
# cat=pageTree/10; type=string; label=Supported doktypes in page tree:Provide a comma-separated list of doktypes for which cache warmup should be available in the page tree context menu.
17+
supportedDoktypes = 1

0 commit comments

Comments
 (0)