View source
<?php
namespace Drupal\shorten\Form;
use Drupal\Core\Form\ConfigFormBase;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Form\FormStateInterface;
class ShortenKeysForm extends ConfigFormBase {
public function getFormId() {
return 'shorten_keys';
}
protected function getEditableConfigNames() {
return [
'shorten.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$config = $this
->config('shorten.settings');
$form['shorten_bitly'] = [
'#type' => 'fieldset',
'#title' => t('Bit.ly and j.mp'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
];
$form['shorten_bitly']['shorten_bitly_login'] = [
'#type' => 'textfield',
'#title' => t('Bit.ly Login'),
'#default_value' => $config
->get('shorten_bitly_login'),
];
$form['shorten_bitly']['shorten_bitly_key'] = [
'#type' => 'textfield',
'#title' => t('Bit.ly API Key'),
'#default_value' => $config
->get('shorten_bitly_key'),
];
$form['shorten_budurl'] = [
'#type' => 'textfield',
'#title' => t('BudURL API Key'),
'#default_value' => $config
->get('shorten_budurl'),
];
$form['shorten_cligs'] = [
'#type' => 'textfield',
'#title' => t('Cligs API Key'),
'#default_value' => $config
->get('shorten_cligs'),
];
$form['shorten_ez'] = [
'#type' => 'textfield',
'#title' => t('Ez API Key'),
'#default_value' => $config
->get('shorten_ez'),
];
$form['shorten_fwd4me'] = [
'#type' => 'textfield',
'#title' => t('Fwd4.me API Key'),
'#default_value' => $config
->get('shorten_fwd4me'),
];
$form['shorten_googl'] = [
'#type' => 'textfield',
'#title' => t('Goo.gl API Key'),
'#default_value' => $config
->get('shorten_googl'),
];
$form['shorten_redirec'] = [
'#type' => 'textfield',
'#title' => t('Redir.ec API Key'),
'#default_value' => $config
->get('shorten_redirec'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$this
->config('shorten.settings')
->set('shorten_bitly_login', $values['shorten_bitly_login'])
->set('shorten_bitly_key', $values['shorten_bitly_key'])
->set('shorten_budurl', $values['shorten_budurl'])
->set('shorten_cligs', $values['shorten_cligs'])
->set('shorten_ez', $values['shorten_ez'])
->set('shorten_fwd4me', $values['shorten_fwd4me'])
->set('shorten_googl', $values['shorten_googl'])
->set('shorten_redirec', $values['shorten_redirec'])
->save();
}
}