我调试了它,问题是
SEO Extension Plugin 正在侦听\Event::listen('backend.form.extendFields' ... ,此事件在backend.form.extendFieldsBefore 之后触发,因此新添加的字段不可翻译。
backend.form.extendFieldsBefore此事件负责将字段转换为translatable字段,因此在此事件之后添加的字段不会显示为translatable。
一旦我有空闲时间,我计划纠正这种行为和 PR 贡献给作者 repo https://github.com/anand-patel/oc-seo-extension
解决方案可能是[需要在插件基本代码中完成]在SEO Extension Plugin中使用backend.form.extendFieldsBefore事件,并且在扩展字段期间它需要直接使用raw config,现在它使用$widget->addFields所以它必须删除它并直接将字段注入config,因此,稍后可以通过RainLab.Translate Plugin 使用backend.form.extendFieldsBefore 事件处理新添加的字段。
所以现在解决方法在您的自定义插件中添加已经支持跨国的字段,或者您可以再次使用 extendFieldsBefore 并使用 raw config 添加字段。
这里我们只是使用简单的解决方案并添加具有可翻译字段类型的覆盖字段
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');
}
});
}
但这是标准解决方案的解决方法,我计划更正此问题并将 PR 推送给作者插件 repo 可能是 -> https://github.com/anand-patel/oc-seo-extension
如有任何疑问,请发表评论。