PHP code example of brilliance / craft-launcher

1. Go to this page and download the library: Download brilliance/craft-launcher library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brilliance / craft-launcher example snippets


use brilliance\launcher\events\RegisterSearchProvidersEvent;
use brilliance\launcher\services\SearchService;
use yii\base\Event;

Event::on(
    SearchService::class,
    SearchService::EVENT_REGISTER_SEARCH_PROVIDERS,
    function(RegisterSearchProvidersEvent $event) {
        $event->providers[] = new MyCustomSearchProvider();
    }
);

use brilliance\launcher\events\RegisterActionsEvent;
use brilliance\launcher\services\ActionService;
use yii\base\Event;

Event::on(
    ActionService::class,
    ActionService::EVENT_REGISTER_ACTIONS,
    function(RegisterActionsEvent $event) {
        $event->actions[] = new MyCustomAction();
    }
);

// Get popular items for current user
$popularItems = Launcher::$plugin->history->getPopularItems(10);

// Clear user's history
$success = Launcher::$plugin->history->clearUserHistory();

// Get usage statistics
$stats = Launcher::$plugin->history->getUserStats();


namespace myplugin\integrations;

use brilliance\launcher\integrations\BaseIntegration;

class MyPluginIntegration extends BaseIntegration
{
    public function getHandle(): string
    {
        return 'my-plugin';
    }

    public function getName(): string
    {
        return 'My Plugin';
    }

    public function getIcon(): string
    {
        // Return SVG markup, image URL, or emoji
        return '<svg>...</svg>';
    }

    public function getSupportedTypes(): array
    {
        // Element types this integration supports
        return ['Entry', 'Category', 'Asset'];
    }

    public function canHandleItem(array $item): bool
    {
        // Check if your plugin is installed and item is valid
        return parent::canHandleItem($item)
            && !empty($item['id']);
    }

    public function getIntegrationData(array $item): ?array
    {
        if (!$this->canHandleItem($item)) {
            return null;
        }

        // Fetch your plugin's data
        $status = $this->getStatus($item['id']);

        return [
            'handle' => $this->getHandle(),
            'name' => $this->getName(),
            'icon' => $this->getIcon(),
            'status' => [
                'label' => $status,
                'type' => 'success', // success, secondary, warning, danger, default
            ],
            'actions' => [
                [
                    'label' => 'Perform Action',
                    'action' => 'my-action',
                    'confirm' => true, // Show confirmation dialog?
                ],
            ],
        ];
    }

    public function executeAction(string $action, array $params): array
    {
        if ($action === 'my-action') {
            // Perform your action
            return $this->successResponse('Action completed!');
        }

        return $this->errorResponse('Unknown action');
    }
}

use craft\base\Plugin;
use yii\base\Event;
use brilliance\launcher\services\IntegrationService;
use brilliance\launcher\services\RegisterIntegrationsEvent;

class MyPlugin extends Plugin
{
    public function init()
    {
        parent::init();

        // Register integration with Launcher
        Event::on(
            IntegrationService::class,
            IntegrationService::EVENT_REGISTER_INTEGRATIONS,
            function(RegisterIntegrationsEvent $event) {
                $event->integrations[] = new MyPluginIntegration();
            }
        );
    }
}

[
    'handle' => 'my-plugin',           // Unique identifier
    'name' => 'My Plugin',             // Display name
    'icon' => '<svg>...</svg>',        // Icon (SVG, URL, or emoji)
    'status' => [
        'label' => 'Active',           // Status text
        'type' => 'success',           // Badge color (success, secondary, warning, danger, default)
    ],
    'actions' => [                     // Optional action buttons
        [
            'label' => 'Do Something', // Button label
            'action' => 'action-id',   // Action identifier
            'confirm' => true,         // Show confirmation?
        ],
    ],
]

// Success response for actions
$this->successResponse('Success!', ['data' => 'value']);

// Error response for actions
$this->errorResponse('Failed!', ['error' => 'details']);

// Logging
$this->logInfo('Info message', ['context' => 'data']);
$this->logError('Error message', ['context' => 'data']);

use craft\base\Plugin;
use brilliance\launcher\Launcher;

class MyPlugin extends Plugin
{
    public function init()
    {
        parent::init();

        // Register drawer content provider
        if (class_exists(Launcher::class)) {
            Launcher::getInstance()->drawer->registerProvider(
                'my-plugin',  // Unique handle
                [$this, 'getDrawerContent'],  // Callback function
                50  // Priority (higher = appears earlier, default is 0)
            );
        }
    }

    /**
     * Get drawer content for the specified context
     *
     * @param string $context The current tab context ('search', 'assistant', etc.)
     * @return array Drawer content structure
     */
    public function getDrawerContent(string $context): array
    {
        // Return different content based on context
        $tips = $context === 'assistant' ? [
            'Use my plugin to enhance your assistant responses',
            'Configure settings in the plugin panel'
        ] : [
            'Press Cmd+Shift+P to open my plugin',
            'Search supports my custom element types'
        ];

        return [
            'title' => 'My Plugin Tips',  // Optional: drawer title (omit to use default)
            'sections' => [
                [
                    'title' => 'Quick Tips',
                    'items' => $tips
                ],
                [
                    'title' => 'Resources',
                    'links' => [
                        [
                            'text' => 'Plugin Documentation',
                            'url' => 'https://myplugin.com/docs',
                            'icon' => 'book'  // star, message, or book
                        ],
                        [
                            'text' => 'Report an Issue',
                            'url' => 'https://github.com/myvendor/my-plugin/issues',
                            'icon' => 'message'
                        ]
                    ]
                ]
            ]
        ];
    }
}

[
    'title' => 'Section Title',  // Optional: appears at top of drawer
    'sections' => [              // Array of content sections
        [
            'title' => 'Section Name',      // Section heading
            'items' => [                    // Array of tip strings
                'First tip or trick',
                'Second helpful hint',
                'Third suggestion'
            ]
        ],
        [
            'title' => 'Links Section',
            'links' => [                    // Array of link objects
                [
                    'text' => 'Link Text',  // Display text
                    'url' => 'https://...',  // Target URL
                    'icon' => 'star'        // Icon: star, message, or book
                ]
            ]
        ]
    ]
]

public function getDrawerContent(string $context): array
{
    $sections = [];

    // Add context-specific tips
    if ($context === 'assistant') {
        $sections[] = [
            'title' => 'Assistant Integration',
            'items' => [
                'Ask the assistant to use my plugin features',
                'Plugin data is automatically available to the assistant'
            ]
        ];
    } else {
        $sections[] = [
            'title' => 'Search Tips',
            'items' => [
                'Search my custom element types',
                'Use * to browse my plugin categories'
            ]
        ];
    }

    // Always 

// Remove provider (typically in plugin uninstall)
Launcher::getInstance()->drawer->unregisterProvider('my-plugin');

'devMode' => true,
'enableTemplateCaching' => false,
bash
   php craft plugin/install launcher