View source
<?php
namespace Drupal\sharemessage\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\sharemessage\Plugin\sharemessage\SocialSharePrivacy;
use Symfony\Component\HttpFoundation\Request;
class SocialSharePrivacySettingsForm extends ConfigFormBase {
protected function getEditableConfigNames() {
return [
'sharemessage.socialshareprivacy',
];
}
public function getFormId() {
return 'sharemessage_social_share_privacy_settings';
}
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$form = parent::buildForm($form, $form_state);
$social_share_privacy_config = $this
->config('sharemessage.socialshareprivacy');
$form['services'] = [
'#title' => $this
->t('Default visible services'),
'#type' => 'select',
'#multiple' => TRUE,
'#options' => SocialSharePrivacy::allServices(),
'#default_value' => $social_share_privacy_config
->get('services'),
'#size' => 11,
];
$form['facebook_action'] = [
'#title' => $this
->t('Choose facebook action'),
'#type' => 'radios',
'#default_value' => $social_share_privacy_config
->get('facebook_action') ?: 'like',
'#options' => [
'like' => $this
->t('Like'),
'recommend' => $this
->t('Recommend'),
],
];
$form['disqus_shortname'] = [
'#title' => $this
->t('Disqus shortname'),
'#type' => 'textfield',
'#description' => $this
->t('You can get shortname from <a href=":url">Disqus</a>.', [
':url' => 'https://disqus.com/',
]),
'#default_value' => $social_share_privacy_config
->get('disqus_shortname'),
];
$form['flattr_uid'] = [
'#title' => $this
->t('Flattr user id'),
'#type' => 'textfield',
'#description' => $this
->t('You can get user id from <a href=":url">Flattr</a>.', [
':url' => 'https://flattr.com/',
]),
'#default_value' => $social_share_privacy_config
->get('flattr_uid'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('sharemessage.socialshareprivacy')
->set('services', $form_state
->getValue('services'))
->set('facebook_action', $form_state
->getValue('facebook_action'))
->set('disqus_shortname', $form_state
->getValue('disqus_shortname'))
->set('flattr_uid', $form_state
->getValue('flattr_uid'))
->save();
}
}