Plugin sidebar order + directory layout from index.md
- PluginManager: iterate allowedPlugins in user-defined order (frontmatter order) - content-edit.twig: plugin list with up/down arrows to set order - Directory listing: read layout/plugins from index.md if present - Directory default layout: full_content (no sidebar) unless index.md says otherwise
This commit is contained in:
@@ -1141,9 +1141,22 @@ class CodePressCMS {
|
||||
$content .= '<p>' . $this->t('directory_empty') . '.</p>';
|
||||
}
|
||||
|
||||
// Check for index.md in this directory for layout/plugins metadata
|
||||
$indexFile = $dirPath . '/index.md';
|
||||
$layout = 'full_content';
|
||||
$metadata = [];
|
||||
if (file_exists($indexFile)) {
|
||||
$indexContent = file_get_contents($indexFile);
|
||||
$parsed = $this->parseMetadata($indexContent);
|
||||
$metadata = $parsed['metadata'];
|
||||
$layout = $metadata['layout'] ?? 'full_content';
|
||||
}
|
||||
|
||||
return [
|
||||
'title' => $title,
|
||||
'content' => $content
|
||||
'content' => $content,
|
||||
'layout' => $layout,
|
||||
'metadata' => $metadata,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -140,28 +140,27 @@ class PluginManager
|
||||
public function getSidebarContent(?array $allowedPlugins = null): string
|
||||
{
|
||||
$sidebarContent = '';
|
||||
|
||||
foreach ($this->plugins as $pluginName => $plugin) {
|
||||
if (!$this->isPluginViewable($plugin) || !method_exists($plugin, 'getSidebarContent')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($allowedPlugins !== null && !in_array($pluginName, $allowedPlugins, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content = $plugin->getSidebarContent();
|
||||
if (trim($content) === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$title = 'Plugin';
|
||||
if (method_exists($plugin, 'getConfig')) {
|
||||
$config = $plugin->getConfig();
|
||||
$title = $config['title'] ?? 'Plugin';
|
||||
}
|
||||
|
||||
$sidebarContent .= '
|
||||
|
||||
// If allowedPlugins is specified, iterate in that order (user-defined order)
|
||||
if ($allowedPlugins !== null) {
|
||||
foreach ($allowedPlugins as $pluginName) {
|
||||
$plugin = $this->plugins[$pluginName] ?? null;
|
||||
if (!$plugin || !$this->isPluginViewable($plugin) || !method_exists($plugin, 'getSidebarContent')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content = $plugin->getSidebarContent();
|
||||
if (trim($content) === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$title = 'Plugin';
|
||||
if (method_exists($plugin, 'getConfig')) {
|
||||
$config = $plugin->getConfig();
|
||||
$title = $config['title'] ?? 'Plugin';
|
||||
}
|
||||
|
||||
$sidebarContent .= '
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">' . htmlspecialchars($title) . '</h5>
|
||||
@@ -170,8 +169,37 @@ class PluginManager
|
||||
' . $content . '
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
} else {
|
||||
// No filter — show all viewable plugins in load order
|
||||
foreach ($this->plugins as $pluginName => $plugin) {
|
||||
if (!$this->isPluginViewable($plugin) || !method_exists($plugin, 'getSidebarContent')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content = $plugin->getSidebarContent();
|
||||
if (trim($content) === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$title = 'Plugin';
|
||||
if (method_exists($plugin, 'getConfig')) {
|
||||
$config = $plugin->getConfig();
|
||||
$title = $config['title'] ?? 'Plugin';
|
||||
}
|
||||
|
||||
$sidebarContent .= '
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">' . htmlspecialchars($title) . '</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
' . $content . '
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $sidebarContent;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user