I need to create a quick, and small plugin for a client, and am having trouble with the official Craft plugin tutorial.
Here is my base plugin code:
<?php
namespace Craft;
class MailchimpedPlugin extends BasePlugin
{
function getName()
{
return Craft::t('Mailchimped');
}
function getVersion()
{
return '1.0';
}
protected function defineSettings() {
return array(
// Very confused about what goes here.
);
}
public function getSettingsHtml() {
return craft()->templates->render('mailchimped/settings', array(
'settings' => $this->getSettings()
));
}
}
And here is my settings page code w/ screenshot of what it looks like on the front end:
{% import '_includes/forms' as forms %}
<div>
{{ forms.textField({
label: "API Key"|t,
id: 'apiKey',
name: 'apiKey',
placeholder: "XXXXXXXXXXXX",
required: true
}) }}
{{ forms.textField({
label: "List ID"|t,
id: 'listId',
name: 'listId',
placeholder: "d0ffd45cbd",
required: true
}) }}
<h3>Help</h3>
<a href="https://kb.mailchimp.com/integrations/api-integrations/about-api-keys" target="_blank">
How To Find Your API Key
</a>
<br />
<a href="https://kb.mailchimp.com/lists/manage-contacts/find-your-list-id" target="_blank">
How To Find Your List ID
</a>
</div>
Basically, all I want to know how to do, is to get the api key and list id field to save and be persisted after the user presses the save button.
I tried reading through the plugin tutorial, and looked at the sample plugin Github page, but honestly, it has to much functionality for a beginner, and is just confusing me even more.
Ideally, the accepted answer will have some code outlining how I would go about this. P.S. I am not looking for an existing plugin, as I want to to do this myself. My company(A studio) uses CraftCMS for their clients websites, so I want to know how to create custom plugins in the future.