LinkIconSettingsForm.php in Link Icon 8
File
src/Form/LinkIconSettingsForm.php
View source
<?php
namespace Drupal\linkicon\Form;
use Drupal\Core\Asset\LibraryDiscoveryInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LinkIconSettingsForm extends ConfigFormBase {
protected $libraryDiscovery;
public function __construct(ConfigFactoryInterface $config_factory, LibraryDiscoveryInterface $library_discovery) {
parent::__construct($config_factory);
$this->libraryDiscovery = $library_discovery;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('library.discovery'));
}
public function getFormId() {
return 'linkicon_settings_form';
}
protected function getEditableConfigNames() {
return [
'linkicon.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('linkicon.settings');
$form['linkicon'] = [
'#type' => 'details',
'#title' => $this
->t('Linkicon settings'),
'#description' => $this
->t('Import a custom icon font CSS located on the file system.'),
'#open' => TRUE,
'#collapsible' => FALSE,
];
$form['linkicon']['font'] = [
'#type' => 'textfield',
'#title' => $this
->t('Icon font CSS file path'),
'#description' => $this
->t('Valid path to CSS file. Use comma separated value for multiple CSS files, e.g.: /libraries/fontello/css/fontello.css, /libraries/fontello/css/other.css. <br />Please be aware of potential namespace conflicts if you import additional icon fonts through a theme, as most icon fonts use the same selectors (.icon:before). <br />Leave it empty if using FontAwesome (5+) module and SVG with JS method, or your theme has already defined one.'),
'#default_value' => $config
->get('font'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('linkicon.settings')
->set('font', $form_state
->getValue('font'))
->save();
$this->libraryDiscovery
->clearCachedDefinitions();
parent::submitForm($form, $form_state);
}
}