I debugged It and The problem is
SEO Extension Plugin
is listening for \Event::listen('backend.form.extendFields' ...
and this event is fired after backend.form.extendFieldsBefore
so new added fields are not translatable.
backend.form.extendFieldsBefore
this event is responsible to convert field in to translatable
field so fields which are added after this event are not shown as translatable
.
I am planning to correct this behavior and PR contribution to author repo https://github.com/anand-patel/oc-seo-extension once i get some free time
Solution could be [ need to be done in plugin base code ] to use backend.form.extendFieldsBefore
event in SEO Extension Plugin
and during extension of fields it need to directly work with raw config
, right now it uses $widget->addFields
so it has to remove that and directly injecting fields to config
so, later on newly added fields can be processed by RainLab.Translate Plugin
using backend.form.extendFieldsBefore
event.
So For now workaround in your custom plugin add fields which are already have support for transnational or you can again use extendFieldsBefore
and work with raw config
to add fields.
here we just use easy solution and add override field with translatable field type
use RainLab\Blog\Models\Post;
use Event;
use System\Classes\PluginManager;
public function register() {
Post::extend(function($post) {
if (!$post->propertyExists('translatable')) {
$post->addDynamicProperty('translatable', []);
}
$post->translatable = array_merge($post->translatable, ['seo_title', 'seo_description' /* so on ....*/]);
});
Event::listen('backend.form.extendFields', function($widget) {
if(PluginManager::instance()->hasPlugin('RainLab.Blog') && $widget->model instanceof \RainLab\Blog\Models\Post)
{
$widget->addFields([
'seo_title' => [
'label' => 'Meta Title',
'type' => 'mltext', //<- HERE
'tab' => 'SEO'
],
'seo_description' => [
'label' => 'Meta Description',
'type' => 'mltextarea', //<- HERE
'size' => 'tiny',
'tab' => 'SEO'
],
'seo_keywords' => [
'label' => 'Meta Keywords',
'type' => 'mltextarea', //<- HERE
'size' => 'tiny',
'tab' => 'SEO'
],
'canonical_url' => [
'label' => 'Canonical URL',
'type' => 'mltext', //<- HERE
'tab' => 'SEO',
'span' => 'left'
],
'redirect_url' => [
'label' => 'Redirect URL',
'type' => 'mltext', //<- HERE
'tab' => 'SEO',
'span' => 'right'
],
// ... so on
],
'secondary');
}
});
}
but this is workaround for standard solution, I am planning to correct this and push PR to author plugin repo may be -> https://github.com/anand-patel/oc-seo-extension
if any doubts please comment.