JukeboxHero
JukeboxHero

Reputation: 115

Add menu entry in LimeSurvey 6.5.9 Plugin

I want to create a plugin for limesurvey 6.5.9 with php 8.1. First, I want to create a menu entry in the top next to Help and Configuration. I tried to find some documentation but it's hard to find any good documentation about it. With the sources I found, I created the following code just for create the menu entry without any functionality. I can install and activate the plugin but I can't see any menu entry. Where is the problem?

Testplugin.php

<?php

class Testplugin extends PluginBase
{
    protected $storage = 'DbStorage';
    static protected $description = "Test Plugin";
    static protected $name = "Testplugin";

    public function init()
    {
        $this->subscribe('onPluginRegistration');
    }

    public function onPluginRegistration()
    {
        $pluginName = $this->get('pluginName');
        $existingMenu = Surveymenu::model()->findByAttributes(['name' => 'testplugin_menu']);
        if (!$existingMenu) {
            $menuArray = [
                "parent_id" => 1,
                "name" => "testplugin_menu",
                "title" => "Manage Companies",
                "position" => "side",
                "description" => "Manage companies"
            ];
            $newMenuId = Surveymenu::staticAddMenu($menuArray);

            $menuEntryArray = [
                "name" => "manage_companies",
                "title" => "Manage Companies",
                "menu_title" => "Manage Companies",
                "menu_description" => "Manage companies",
                "menu_icon" => "building",
                "menu_icon_type" => "fontawesome",
                "menu_link" => "admin/pluginhelper/sa/index/plugin/Testplugin",
                "addSurveyId" => false,
                "addQuestionGroupId" => false,
                "addQuestionId" => false,
                "linkExternal" => false,
                "hideOnSurveyState" => null,
                "manualParams" => ""
            ];
            SurveymenuEntries::staticAddMenuEntry($newMenuId, $menuEntryArray);
        }
    }
}

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <metadata>
        <name>Testplugin</name>
        <type>plugin</type>
        <creationDate>2024-05-01</creationDate>
        <lastUpdate>2024-05-28</lastUpdate>
        <author>Peter Parker</author>
        <authorUrl>https://www.example.com</authorUrl>
        <version>1.0.0</version>
        <license>Empty</license>
        <description><![CDATA[Testplugin]]></description>
    </metadata>

    <compatibility>
        <version>6.5.9</version>
    </compatibility>

    <settings>
        <setting>
            <name>placeholder</name>
        </setting>
    </settings>
</config>

Upvotes: 0

Views: 78

Answers (1)

Vo Tan Dat
Vo Tan Dat

Reputation: 1

Refer to this manual: https://manual.limesurvey.org/Extra_menus_event Your plugin code should look like

<?php
class Testplugin extends PluginBase
{
    static protected $description = 'Test plugin';
    static protected $name = 'Testplugin';

    public function init() {
        $this->subscribe('beforeAdminMenuRender', 'custom_admin_menu');
    }

    public function custom_admin_menu() {
        $event = $this->getEvent();
        $buttonTestOptions = [
          'buttonId' => 'test-button',
          'label' => 'Test button',
          'href' => 'https://limesurvey.org',
          'iconClass' => 'fa fa-link',
          'openInNewTab' => true,
          'isPrepended' => false,
          'tooltip' => 'You can add a tooltip here',
        ];
        $menuTestButton = new \LimeSurvey\Menu\MenuButton($buttonTestOptions);
        $event->append('extraMenus', [$menuTestButton]);
    }

}

Upvotes: 0

Related Questions