am-impact/amcommand

Command palette in Craft.

Installs: 73 720

Dependents: 3

Suggesters: 0

Security: 0

Stars: 87

Watchers: 10

Forks: 8

Open Issues: 12

Type:craft-plugin

3.1.4 2018-05-30 07:07 UTC

README

Command palette in Craft.

Requirements

This plugin requires Craft CMS 3.0.0-RC1 or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require am-impact/amcommand
    
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Command Palette.

Functionality

If you have ever used Alfred, you know you'll be zipping through the control panel in no time!

You can open the command palette by using the keyboard combination: (command key for Apple users) CTRL + SHIFT + P, or you click on Command in the CP navigation.

Use the keyboard arrows (up and down) to navigate to your desired command. When you hit the return key or click on a command, the command palette will navigate to the location and show what it's loading. Use (command key for Apple users) CTRL + RETURN (or click) to fire the command in a new window.

Palette

Current commands

Default commands

Special commands

Adding your own commands

If you'd like to add commands for a plugin you're developing, register the commands through an event.

Add this at the top of your main plugin file:

use amimpact\commandpalette\events\RegisterCommandsEvent;
use amimpact\commandpalette\services\General;
use yii\base\Event;

Add this to the init function of your main plugin file:

if (class_exists(General::class)) {
    Event::on(General::class, General::EVENT_REGISTER_COMMANDS, function(RegisterCommandsEvent $event) {
        $event->commands[] = [
            'name' => 'Search on Google',
            'type' => 'Custom',
            'url'  => 'http://www.google.nl',
            'icon' => [
                'type' => 'font',
                'content' => 'plugin'
            ]
        ];
        $event->commands[] = [
            'name' => 'My own plugin function in a service',
            'type' => 'Custom',
            'call' => 'yourPluginFunctionName',
            'plugin' => 'your-plugin-handle',
            'service' => 'yourPluginServiceName'
        ];
    });
}

That's it! The command palette will add these two commands.

If you look at the second example, you see a call, plugin and service key. These can be used to load a new set of commands.

In your plugin's service yourPluginServiceName (e.g.: general), you'll create a new function called yourPluginFunctionName. In here you could do the same thing as you see in the example, and just return the new set of commands.

Contact

If you have any questions or suggestions, don't hesitate to contact us. We would like to add more commands to the palette, so if you have any ideas then please let us know!