1

I‘m a newbie and I’m learning to create simple portfolio-type sites using Craft CMS. I‘d like to remove the Plugin Store from the admin panel in the Production Environment because basically, I don't need to install plugins and the product environment plugin store is just read-only mode. I have checked the official documentation and the community without any information about it.

1

You can use an event hook for the event Cp::EVENT_REGISTER_CP_NAV_ITEMS to modify the Control Panel navigation – see Control Panel Sections in the documentation. To determine if the site is in devMode, you can use the config service. Here's a little module that removes the plugin store from the navigation elements unless the site is in dev mode:

<?php

namespace modules\Site;

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

class SiteModule extends \yii\base\Module
{
    public function init()
    {
        Event::on(
            Cp::class,
            Cp::EVENT_REGISTER_CP_NAV_ITEMS,
            function(RegisterCpNavItemsEvent $event) {
                if (Craft::$app->config->general->devMode) return;
                $pluginStoreIndex = array_search(
                    'plugin-store',
                    array_column($event->navItems, 'url')
                );
                if ($pluginStoreIndex === false) return;
                unset($event->navItems[$pluginStoreIndex]);
            }
        );

        parent::init();
    }
}

To make this work, you need to put that code into a site module and add it to the bootstrap section in the app.php config. See How to Build a Module for details.

3
  • I have solved this problem with your guidance, thank you so much!
    – Colt
    Aug 24 at 9:05
  • @Colt Glad I could help! Would you mind marking my answer as accepted? Thanks!
    – MoritzLost
    Aug 24 at 12:21
  • Thank you again!
    – Colt
    Aug 24 at 15:29
1

You can also use the CP Nav plugin

1
  • Thank you very much!
    – Colt
    Aug 24 at 9:06
1

I must say that I don't understand the rationale behind hiding the Settings in production but not the Plugin Store.

The only action you can really do in production is upgrade to a Pro licence if you don't have one already, so this might be the reason but I think the link at the bottom of the page there if you need it.

For me the 'allowAdminChanges' => false should also hide the Plugin Store or another trigger like 'showPluginStore' should be added.

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.