SocialUserExportSettingsForm.php in Open Social 10.1.x
File
modules/social_features/social_user_export/src/Form/SocialUserExportSettingsForm.php
View source
<?php
namespace Drupal\social_user_export\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\social_user_export\Plugin\UserExportPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SocialUserExportSettingsForm extends ConfigFormBase {
protected $exportPluginManager;
public function __construct(ConfigFactoryInterface $config_factory, UserExportPluginManager $export_plugin_manager) {
parent::__construct($config_factory);
$this->exportPluginManager = $export_plugin_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('plugin.manager.user_export_plugin'));
}
protected function getEditableConfigNames() {
return [
'social_user_export.settings',
];
}
public function getFormId() {
return 'social_user_export_settings_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('social_user_export.settings');
$options = [];
$export_plugins = $this->exportPluginManager
->getDefinitions();
foreach ($export_plugins as $plugin) {
$options[$plugin['id']] = $plugin['label'];
}
$form['plugins'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Data available for users to export'),
'#description' => $this
->t('Check any data that users are allowed to export in for example the events and groups they manage.'),
'#options' => $options,
'#default_value' => $config
->get('plugins'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('social_user_export.settings')
->set('plugins', $form_state
->getValue('plugins'))
->save();
}
}