I want to extends the Blog plugin by changing the property $allowedSortingOptions
and also the scopeListFrontEnd()
scope.
The property defines the sorting options available and I want to add some other options. Original value from Blog Post.php :
public static $allowedSortingOptions = [
'title asc' => 'rainlab.blog::lang.sorting.title_asc',
'title desc' => 'rainlab.blog::lang.sorting.title_desc',
'created_at asc ' => 'rainlab.blog::lang.sorting.created_asc',
'created_at desc' => 'rainlab.blog::lang.sorting.created_desc',
'updated_at asc' => 'rainlab.blog::lang.sorting.updated_asc',
'updated_at desc' => 'rainlab.blog::lang.sorting.updated_desc',
'published_at asc' => 'rainlab.blog::lang.sorting.published_asc',
'published_at desc' => 'rainlab.blog::lang.sorting.published_desc',
'random' => 'rainlab.blog::lang.sorting.random'
];
I want also to extend the scope logic. Original method from Blog Post.php :
public function scopeListFrontEnd($query, $options)
{
// Code ...
return $query->paginate($perPage, $page);
}
In my plugin I tried several ways to do this inside the Plugin.php file.
private function extendModel()
{
// Code ...
PostModel::extend(function ($model) {
// Code ...
// This does not work
// I want to override $setAllowedSortingOptions here and add other options
$model::$allowedSortingOptions = [
// My Options
];
// This does not work either
$model->addDynamicProperty('allowedSortingOptions', $MyOptions);
// I want to retrieve the result query of the scope ListFrontEnd to change it
Event::listen('backend.filter.extendQuery', function($filterWidget, $query, $scope) {
if ($scope->scopeName == 'listFrontEnd') {
// Change the $query order here
}
});
});
}
- So, how can I override a Class property ?
- And how can I extends/override a Scope or Method ?
Thanks.