This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello,
I'm trying to extend the blog plugin with translatable functionality.
I made a plugin (Acme.Blog) and I got a model with the following code:
<?php namespace Acme\Blog\Models;
use Model;
class Post extends Model
{
/**
* @var array Translatable fields
*/
public $translatable = ['excerpt'];
/**
* Add translation support to this model, if available.
* @return void
*/
public static function boot()
{
// Call default functionality (required)
parent::boot();
// Check the translate plugin is installed
if (!class_exists('RainLab\Translate\Behaviors\TranslatableModel'))
return;
// Extend the constructor of the model
self::extend(function($model){
// Implement the translatable behavior
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel';
});
}
}
In my plugin.php :
<?php namespace Acme\Blog;
use System\Classes\PluginBase;
use RainLab\Blog\Models\Post as BlogPost;
/**
* Blog Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'Blog',
'description' => 'No description provided yet...',
'author' => 'Acme',
'icon' => 'icon-leaf'
];
}
public function boot()
{
BlogPost::extend(function($model) {
$model->implement[] = 'Acme.Blog.Models.Post';
});
}
}
I'm getting an error:
Argument 1 passed to October\Rain\Database\Model::__construct() must be of the type array, object given, called in /var/www/vdlp/public_html/vendor/october/rain/src/Extension/ExtendableTrait.php on line 137 and defined
Something is wrong in the boot function, but what is it, how do I extend the blog plugin with translation functionality?
Last updated
$model->implement[] = 'Acme.Blog.Models.Post'; -> must be of the type array, object given
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel'; -> same story here too...
Last updated
r_w4024 said:
$model->implement[] = 'Acme.Blog.Models.Post'; -> must be of the type array, object given
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel'; -> same story here too...
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel'; This 1 is right.... is from the docs, but I have no idea what the other one has to be to achieve this?
Tiger said:
r_w4024 said:
$model->implement[] = 'Acme.Blog.Models.Post'; -> must be of the type array, object given
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel'; -> same story here too...
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel'; This 1 is right.... is from the docs, but I have no idea what the other one has to be to achieve this?
Hmm, finally read all of your code, seems you are doing something strange... Which tutorial you followed? Can you post the link? Seems you successfully implemented translatable model trait in Acme.Blog Model, after that you are trying to do something very strange - you are trying to mix Rainlab.Blog Model with Acme Blog Model. You want to get translatable trait for Rainlab.Blog Model or you need something else?
Last updated
r_w4024 said:
Tiger said:
r_w4024 said:
$model->implement[] = 'Acme.Blog.Models.Post'; -> must be of the type array, object given
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel'; -> same story here too...
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel'; This 1 is right.... is from the docs, but I have no idea what the other one has to be to achieve this?
Hmm, finally read all of your code, seems you are doing something strange... Which tutorial you followed? Can you post the link? Seems you successfully implemented translatable model trait in Acme.Blog Model, after that you are trying to do something very strange - you are trying to mix Rainlab.Blog Model with Acme Blog Model. You want to get translatable trait for Rainlab.Blog Model or you need something else?
Yes, I'm trying to add the translatable functionality into the existing Rainlab.Blog by extending the Rainlab.Blog plugin.
Ok, then you need to extend RainLab.Blog model not Acme.Blog model. Actually you don't need Acme.Blog model at all. Check this url first: https://vimeo.com/108040919
In plugin.php you should have something like this:
public function boot()
{
// Check the translate plugin is installed
if (!class_exists('RainLab\Translate\Behaviors\TranslatableModel'))
return;
// Extend the constructor of the model
BlogPost::extend(function($model){
// Implement the translatable behavior
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel';
});
}
It should work but I haven't tested it. Give your feedback... :)
I am unsure about this part:
// Call default functionality (required)
parent::boot();
It is starting system model before adding translatable trait to model. Do we still need that if we are extending other model?
Last updated
Awesome, that works :) Thanks for your help, the code is like this now:
public function boot()
{
// Check the translate plugin is installed
if (!class_exists('RainLab\Translate\Behaviors\TranslatableModel'))
return;
// Extend the constructor of the model
BlogPost::extend(function($model){
$model->translatable = ['excerpt'];
// Implement the translatable behavior
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel';
});
}
Sorry forgot about:
$model->translatable = ['excerpt'];
I'm still learning October... :)
Last updated
raw99 said:
Sorry forgot about:
$model->translatable = ['excerpt'];
I'm still learning October... :)
No problem mate :)
@dogiedog,
How to extend the content of rainlab.blog?
I want to use richeditor as translatable for the content. But the button 'EN' on the right top doesn't appear.
thanks
1-12 of 12