We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How to provide dynamic settings in an extension? Please help.

Development and Programming

Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

I was just wondering how to do something so thought I would ask on here as I know that there are a lot of excellent developers out there just wanting to lend a hand 😉

I was wondering how I can go about getting an extension settings page which has something like the following :

Weblog One Field One Field Two Weblog Two Field One Field Two

Basically where the Weblog One, Weblog Two text is shown above these would show all your weblogs which would repeat for as many weblogs that there are in the system so if you for instance added a new weblog at any time in the future another instance of the settings would appear. The Field One, Field Two settings would be drop-down menus which would list all the custom fields that are assigned to that weblog. This would then allow you to choose two fields for each weblog that I could then use in the extension code.

Basically my question is two-fold as I really don’t have much of an idea of where to start on this one.

Firstly, how do I get the settings page to show this and dynamically? Second, how do I then utilise (grab) these settings from inside the extension?

Hope that made some sense and someone can help on this.

Any help would be greatly appreciated.

Best wishes,

Mark

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Hey Mark, you would use one of the settings field types that fits your need (radio, multi-select, etc.). You can use the Database class to fetch that information to populate the fields in the settings() method. As an example, this would represent a member group multi-select:

$query = $DB->query("SELECT group_id, group_title FROM exp_member_groups WHERE group_id NOT IN ('2', '3', '4')");

$groups = array();

foreach ($query->result as $row)
{
    $groups[$row['group_id']] = $row['group_title'];
}

$settings['member_groups'] = array('ms', $groups, '');
       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Hi Derek,

Thanks for that, will look into it a bit later on and see where I get to.

Best wishes,

Mark

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

No problem. After trying that out, in your extension’s method that fires, do this so you can see how the data is made available to you:

echo '<pre>';print_r($this->settings);echo'</pre>

<p>‘;exit;
</pre>

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Thanks, will try all that and see where I get to.

I hope not to have to come back again but may do if it doesn’t go as easily as I am hoping 😉

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Hi Derek,

Okay just getting around to starting to write the extension and already I’m a little confused. I have the extension installing and showing a settings page with the code that you showed above (reflected here again below) :

$query = $DB->query("SELECT group_id, group_title FROM exp_member_groups WHERE group_id NOT IN ('2', '3', '4')");

$groups = array();

foreach ($query->result as $row)
{
    $groups[$row['group_id']] = $row['group_title'];
}

$settings['member_groups'] = array('ms', $groups, '');

I have to say that I’m a little perplexed as to where the settings page is getting the Member Groups title from. Next to the multi-select field are shown those words but if I try to add in one of the examples from the documentation such as :

$settings['butter']    = "Quite Tasty";

all I get is the text field but without a title shown on the left of the field explaining what it’s for. How come the Member Groups example that you have provided has this text but the others from the documentation example don’t?

How do I get my own titles to appear?

Thanks.

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Also just noticed something else a little weird (well it seemed weird to me anyway 😉 ). I tried out this from the documentation too :

$settings['buttery']   = array('r', array('yes' => "yes", 'no' => "no"), 'no');

If I change the yes’s to some other word and also the no’s to some other word then I do get the radio buttons but they don’t have anything written next to them. I think I’m obviously missing something here so any help on this would be greatly appreciated.

Sorry about all of this, I was really hoping to get this on my own but just following the documentation got me a little lost I’m afraid :-(

Best wishes,

Mark

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

You need to have words in your extension’s language file for each key, Mark. :-D

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen
You need to have words in your extension’s language file for each key, Mark. :-D

Now do I feel silly or what 😉

Although still the question has to be, how come the code that you showed for member groups has the words Member Groups appear next to it?

Thanks.

Best wishes,

Mark

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

It’s already defined in lang.admin.php.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen
It’s already defined in lang.admin.php.

Ah right so that gets added by default I see. Sorry just came across that in the documents. Found a couple of typos I think as well so will post them later on the the Bug Tracker if you want?

Best wishes,

Mark

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Yep sounds fine, Mark, thank you.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.