This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Mdg98
Mdg98

Hi, if i define a a context menu in setting model (https://octobercms.com/docs/plugin/settings#settings-page-context) and get a setting values in a model class of my plugin to retrieve some values to use it as a option list for a dropdown field, a settings menu appear in create and update model view, but if i remove

BackendMenu::setContext('October.System', 'system', 'settings')

from a Settings model all it's ok. It's normal behaviour? I'm doing something wrong?

Last updated

mjauvin
mjauvin

I don't have enough information to help. Can you post the model + controller and explain the issue with more details?

Mdg98
Mdg98

Hi mjauvin, controller and model are new and almost empty

Model

namespace Mdg98\Vet\Models;

use Model;
use Mdg98\Vet\Models\Settings;
use October\Rain\Support\Collection;

class Pet extends Model
{
    use \October\Rain\Database\Traits\Validation;

    use \October\Rain\Database\Traits\SoftDelete;

    protected $dates = ['deleted_at'];

    public $table = 'mdg98_vet_pets';

   public $rules = [

   ];

   public function getReferralsOptions()
   {
        $referrals= new Collection(Settings::get('referrals'));
        return $referrals->lists('referral');
   }

}

Controller

namespace Mdg98\Vet\Controllers;

use Backend\Classes\Controller;
use BackendMenu;

class Pets extends Controller
{
    public $implement = [
        'Backend\Behaviors\ListController',
        'Backend\Behaviors\FormController'
   ];

    public $listConfig = 'config_list.yaml';
    public $formConfig = 'config_form.yaml';

    public function __construct()
    {
        parent::__construct();
        BackendMenu::setContext('Mdg98.Mop', 'main-vet-menu-item');
    }
}

Settings Model

namespace Mdg98\Vet\Models;

use Model;
use BackendMenu;
use System\Classes\SettingsManager;

class Settings extends Model
{

    public function __construct()
    {
        parent::__construct();

        // BackendMenu::setContext('October.System', 'system', 'settings');
        SettingsManager::setContext('Mdg98.Vet', 'settings');
    }

    public $implement = ['System.Behaviors.SettingsModel'];

    public $settingsCode = 'mdg98_vet_settings';

    public $settingsFields = 'fields.yaml';

    public $attributes = [];

    public $requiredPermissions = [];

}

if I remove the comment from the line

BackendMenu::setContext('October.System', 'system', 'settings');

a settings menu appear in create and update view of Pets controller.

Thank you in advance for your help

Last updated

mjauvin
mjauvin

BackendMenu::setContext call should be in your controller's constructor...

Last updated

mjauvin
mjauvin

Did you register you settings model in your plugin?

(see here: https://octobercms.com/docs/plugin/settings#link-registration)

Last updated

mjauvin
mjauvin

You shouldn't need a SettingsManager::setContext in your Settings model

Mdg98
Mdg98

mjauvin said:

BackendMenu::setContext call should be in your controller's constructor...

Oops..I moved it to the controller but the behavior doesn't change

Mdg98
Mdg98

mjauvin said:

Did you register you settings model in your plugin?

(see here: https://octobercms.com/docs/plugin/settings#link-registration)

yes

Mdg98
Mdg98

mjauvin said:

You shouldn't need a SettingsManager::setContext in your Settings model

I have removed all

public function __construct()
{
    parent::__construct();

    BackendMenu::setContext('October.System', 'system', 'settings');
    SettingsManager::setContext('Mdg98.Vet', 'settings');
}

from everywhere and all works fine.

ok, I understand, these indications https://octobercms.com/docs/plugin/settings#settings-page-context it's valid only if i create a link to a specific back-end page and not if i use a link to a settings model as shown here https://octobercms.com/docs/plugin/settings#link-registration

Thanks mjauvin

Last updated

1-9 of 9

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.