Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function pluginDetails(): array
public function boot(): void
{
$this->extendPagesForms();
$this->extendWinterBlogPlugin();
$this->populateGlobalTags();
}

Expand Down Expand Up @@ -178,7 +179,53 @@ protected function populateGlobalTags()
}
}
});
}

/**
* Extends the Winter.Blog plugin with support for SEO form fields
* @TODO: Replace with a more generic approach that can be enabled / disabled / configured via config file
*/
protected function extendWinterBlogPlugin(): void
{
$controllerModels = [
\Winter\Blog\Controllers\Posts::class => [
\Winter\Blog\Models\Post::class,
],
\Winter\Blog\Controllers\Categories::class => [
\Winter\Blog\Models\Category::class,
],
];

Event::listen('backend.form.extendFieldsBefore', function (\Backend\Widgets\Form $widget) use ($controllerModels) {
if ($widget->isNested) {
return;
}

$controller = $widget->getController();
$model = $widget->model;

if (
!isset($controllerModels[get_class($controller)])
|| !in_array(get_class($model), $controllerModels[get_class($controller)])
) {
return;
}

$prefix = 'metadata[seo][';

$form = Yaml::parseFile(plugins_path('winter/seo/models/meta/fields.yaml'));
$tab = 'winter.seo::lang.models.meta.label';
$halcyonFields = [];
foreach ($form['fields'] as $name => $config) {
$config['tab'] = $tab;
$halcyonFields["{$prefix}{$name}]"] = $config;
}

$widget->secondaryTabs['paneCssClass'][$tab] = 'padded-pane';
$widget->secondaryTabs['icons'][$tab] = 'icon-magnifying-glass';

$widget->secondaryTabs['fields'] = array_merge($widget->secondaryTabs['fields'], $halcyonFields);
});
}

/**
Expand Down