View source
<?php
namespace Drupal\slick_ui\Form;
use Drupal\slick\SlickDefault;
use Drupal\slick\SlickManagerInterface;
class SlickSettingsForm {
protected $manager;
public function __construct(SlickManagerInterface $manager) {
$this->manager = $manager;
}
public function getFormId() {
return 'slick_settings_form';
}
public function buildForm() {
$form['module_css'] = [
'#type' => 'checkbox',
'#title' => t('Enable Slick module slick.theme.css'),
'#description' => t('Uncheck to permanently disable the module slick.theme.css, normally included along with skins.'),
'#default_value' => $this->manager
->config('module_css', TRUE),
'#prefix' => t("Note! Slick doesn't need Slick UI to run. It is always safe to uninstall Slick UI once done with optionsets."),
];
$form['slick_css'] = [
'#type' => 'checkbox',
'#title' => t('Enable Slick library slick-theme.css'),
'#description' => t('Uncheck to permanently disable the optional slick-theme.css, normally included along with skins.'),
'#default_value' => $this->manager
->config('slick_css', TRUE),
];
$form['deprecated'] = [
'#type' => 'checkbox',
'#title' => t('Include deprecated functions (BC)'),
'#description' => t('Only uncheck once Slick views or Slick entityreference is updated from 2.x to 3.x, _only if using any. Until then keep it checked for backward compatibility (BC).'),
'#default_value' => $this->manager
->config('deprecated', TRUE),
];
$form['deprecated_formatter'] = [
'#type' => 'checkbox',
'#title' => t('Include deprecated formatters (BC)'),
'#description' => t('You can safely uncheck, once the provided update is successful. Verify that Slick carousel (deprecated) has been changed into just Slick carousel at Field UI. Otherwise keep it enabled till you change them. Be sure to clear cache!'),
'#default_value' => $this->manager
->config('deprecated_formatter', TRUE),
];
$form['#submit'][] = 'slick_ui_submit_form';
return system_settings_form($form);
}
public function submitForm($form, &$form_state) {
$defaults = SlickDefault::formSettings();
$data = [];
$this->manager
->typecast($form_state['values'], 'slick.settings', TRUE);
foreach ($defaults as $key => $value) {
if (isset($form_state['values'][$key])) {
$data[$key] = $form_state['values'][$key];
}
}
variable_set('slick.settings', $data);
foreach ($defaults as $key => $value) {
if (isset($form_state['values'][$key])) {
unset($form_state['values'][$key]);
}
}
}
}