Select in the config section

Creating and modifying plugins.
Post Reply
Maliuta
Regular
Posts: 6
Joined: Tue Jul 20, 2004 7:27 pm
Location: Brisbane, Australia
Contact:

Select in the config section

Post by Maliuta »

Hi .... again :)

I am trying to add a simple select statment to my plugin's config, I looked at the code for serendipity_plugin_eventwrapper and, after sorting out what went into the array, copied it's way of adding a select.

this is the code I copied

Code: Select all

    function introspect_config_item($name, &$propbag)
    {
        global $serendipity;
        
        switch($name) {
            case 'event_plugin':
                $plugins = serendipity_plugin_api::get_event_plugins();
                $select = array();

                if (is_array($plugins)) {
                    foreach($plugins AS $plugname => $plugarray) {
                        $select[$plugname] = $plugarray['t'];
                    }
                }
                $propbag->add('type',        'select');
                $propbag->add('name',        PLUGIN_EVENT_WRAPPER_PLUGIN);
                $propbag->add('description', PLUGIN_EVENT_WRAPPER_PLUGINDESC);
                $propbag->add('select_values', $select);
                break;

            case 'title':
                $propbag->add('type',        'string');
                $propbag->add('name',        TITLE);
                $propbag->add('description', PLUGIN_EVENT_WRAPPER_TITLEDESC);
                break;

            default:
                    return false;
        }
        return true;
    }
and here is my code

Code: Select all

    function introspect_config_item($name, &$propbag) {

        
        switch ($name) {
            case 'title':
                $propbag->add('type', 'string');
                $propbag->add('name', PLUGIN_SIDEBAR_METAR_TITLE);
                $propbag->add('description', PLUGIN_SIDEBAR_METAR_TITLE_BLAHBLAH);
                break;
            case 'metar':
                $propbag->add('type', 'string');
                $propbag->add('name', PLUGIN_SIDEBAR_METAR_SOURCE);
                $propbag->add('description', PLUGIN_SIDEBAR_METAR_SOURCE_BLAHBLAH);
                break;
            case 'timezone':
                $propbag->add('type', 'string');
                $propbag->add('name', PLUGIN_SIDEBAR_METAR_TIMEZONE);
                $propbag->add('description', PLUGIN_SIDEBAR_METAR_TIMEZONE_BLAHBLAH);
                break;
            case 'unitMeasure':
                $select = array();
                $select["metric"] = "Metric";
                $select["standard"] = "Imperial/US Standard";
                
                $propbag->add('type', 'select');
                $propbag->add('name', PLUGIN_SIDEBAR_METAR_UNITS);
                $propbag->add('description', PLUGIN_SIDEBAR_METAR_UNITS_BLAHBLAH);
                $propbag->add('select_values', $select);
            default:
                return false;
        }

        return true;
    }
I can't see a difference. Mine does display the select box, the html is even correct, it just doesn't save the value from the select to the db where as the other one does.


Nikolai[/code]
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Select in the config section

Post by garvinhicking »

You are missing the 'break;' statement in your case. In your case it goes on to default and there returns 'false'. But you need to return true after a successful case.

Regards,
Garvin.
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Maliuta
Regular
Posts: 6
Joined: Tue Jul 20, 2004 7:27 pm
Location: Brisbane, Australia
Contact:

Thanks

Post by Maliuta »

Thnks for that, that is the kind of thing I probably wouldn't have picked up for ages.

Remember boys and girls don't code while fatiuged: rest, revive and survive :)

Nikolai
Post Reply