nystudio107 / generator-craftplugin

generator-craftplugin is a Yeoman generator for Craft CMS plugins
MIT License
73 stars 30 forks source link

Create CP Nav #35

Closed mccombs closed 7 years ago

mccombs commented 7 years ago

Still scratching my head on this. I took a look at the Redirect Plugin and I thought it was as simple as

use craft\events\RegisterCpNavItemsEvent; and public function getCpNavItem() { return [ 'url'=> 'newsblast', 'label'=>Craft::t('newsblast', 'Newsblast'), 'icon' => 'icon' ]; } but Brandon says you have to run this through a cache event? https://github.com/craftcms/cms/issues/1838

Could the generator include an option for a control panel nav item?

johnfmorton commented 7 years ago

Hello Adam. Please get in touch with me. You've got my contact info.

khalwat commented 7 years ago

I think maybe @brandonkelly copied the wrong code sample, it should be:

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

Event::on(Cp::class, Cp::EVENT_REGISTER_CP_NAV_ITEMS, function(RegisterCpNavItemsEvent $event) {
    if (\Craft::$app->user->identity->admin) {
        $event->navItems['foo'] = [
            'label' => \Craft::t('myplugin', 'Utils'),
            'url' => 'utils'
        ];
    }
});