InstagramBlockForm.php in Instagram Block 8
File
src/Form/InstagramBlockForm.php
View source
<?php
namespace Drupal\instagram_block\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
class InstagramBlockForm extends ConfigFormBase {
public function getFormID() {
return 'instagram_block_config_form';
}
protected function getEditableConfigNames() {
return [
'instagram_block.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('instagram_block.settings');
$form['authorise'] = array(
'#markup' => t('Instagram Block requires connecting to a specific Instagram account. You need to be able to log into that account when asked to. The <a href="!help">Authenticate with Instagram</a> page helps with the setup.', array(
'%link' => 'https://www.drupal.org/node/2746185',
)),
);
$form['user_id'] = array(
'#type' => 'textfield',
'#title' => t('User Id'),
'#description' => t('Your unique Instagram user id. Eg. 460786510'),
'#default_value' => $config
->get('user_id'),
);
$form['access_token'] = array(
'#type' => 'textfield',
'#title' => t('Access Token'),
'#description' => t('Your Instagram access token. Eg. 460786509.ab103e5.a54b6834494643588d4217ee986384a8'),
'#default_value' => $config
->get('access_token'),
);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$user_id = $form_state
->getValue('user_id');
$access_token = $form_state
->getValue('access_token');
$this
->config('instagram_block.settings')
->set('user_id', $user_id)
->set('access_token', $access_token)
->save();
parent::submitForm($form, $form_state);
}
}