1

I want to control my plugin on the admin navbar but I can't found a way for that.

0

When you generate Craft CMS plugin and module code scaffolding on https://pluginfactory.io/ please turn on switch for CP section and then your plugin path/src/.php file in change $hasCpSection true.

Once you do the above changes your plugin will display on the nav bar.

I think this will solve your problem.

2

You need to use the EVENT_REGISTER_CP_NAV_ITEMS event in the main plugin class. From the docs:

use craft\events\RegisterCpNavItemsEvent;
use craft\web\twig\variables\Cp;
use yii\base\Event;

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

    Event::on(
        Cp::class,
        Cp::EVENT_REGISTER_CP_NAV_ITEMS,
        function(RegisterCpNavItemsEvent $event) {
            $event->navItems[] = [
                'url' => 'section-url',
                'label' => 'Section Label',
                'icon' => '@mynamespace/path/to/icon.svg',
            ];
        }
    );

    // ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.