View source
<?php
namespace Drupal\statusmessage\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Config\ConfigFactory;
class instagramApiForm extends FormBase {
protected $configFactory;
private $instagramConfig;
public function __construct(ConfigFactory $config_factory) {
$this->configFactory = $config_factory;
$this->instagramConfig = $this->configFactory
->getEditable('instagram_api.settings');
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'));
}
public function getFormId() {
return 'instagram_api_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$muhTokens = $this->instagramConfig
->get('oauth_access_token');
$form['oauth_access_token'] = [
'#type' => 'textfield',
'#title' => $this
->t('Oauth Access Token'),
'#maxlength' => 64,
'#size' => 64,
'#value' => $this->instagramConfig
->get('oauth_access_token'),
];
$form['oauth_access_token_secret'] = [
'#type' => 'textfield',
'#title' => $this
->t('Oauth Access Token Secret'),
'#maxlength' => 64,
'#size' => 64,
'#value' => $this->instagramConfig
->get('oauth_access_token_secret'),
];
$form['consumer_key'] = [
'#type' => 'textfield',
'#title' => $this
->t('Consumer Key'),
'#maxlength' => 64,
'#size' => 64,
'#value' => $this->instagramConfig
->get('consumer_key'),
];
$form['consumer_secret'] = [
'#type' => 'textfield',
'#title' => $this
->t('Consumer Secret'),
'#maxlength' => 64,
'#sizeue' => 64,
'#value' => $this->instagramConfig
->get('consumer_secret'),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
foreach ($form_state
->getValues() as $key => $value) {
drupal_set_message($key . ': ' . $value);
}
if ($form_state
->getValue('oauth_access_token')) {
$this->instagramConfig
->set('consumer_key', $form_state
->getValue('consumer_key'))
->save();
$this->instagramConfig
->set('consumer_secret', $form_state
->getValue('consumer_secret'))
->save();
$this->instagramConfig
->set('oauth_access_token', $form_state
->getValue('oauth_access_token'))
->save();
$this->instagramConfig
->set('oauth_access_token_secret', $form_state
->getValue('oauth_access_token_secret'))
->save();
}
}
}