Skip to content
Snippets Groups Projects

Issue #3397732: Configuration option to set which version of Bootstrap is being used

Closed Issue #3397732: Configuration option to set which version of Bootstrap is being used
Closed mmarler requested to merge bootstrap_horizontal_tabs-3397732-config into 2.x
3 files
+ 110
0
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 98
0
<?php
namespace Drupal\bootstrap_horizontal_tabs\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configure settings for the utnews module.
*/
class BaseConfigurationForm extends ConfigFormBase {
/**
* The Config Factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The EntityTypeManager.
*
* @var \Drupal\Core\Entity\EntityTypeManager
*/
protected $entityTypeManager;
/**
* Class constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration object factory.
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
* The entity type manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManager $entity_type_manager) {
parent::__construct($config_factory);
$this->entityTypeManager = $entity_type_manager;
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('entity_type.manager')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'bootstrap_horizontal_tabs_general_config';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$map = ['3'=>'0','4'=>'1','5'=>'2'];
$version = $this->config('bootstrap_horizontal_tabs.settings')->get('version');
$form['intro']['#markup'] = $this->t('<p>Please select your Bootstrap verion.</p>');
$form['version'] = [
'#title' => '',
'#type' => 'radios',
'#options' => [
$this->t('Bootstrap 3'),
$this->t('Bootstrap 4'),
$this->t('Bootstrap 5'),
],
'#default_value' => $map[$version],
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$map = ['0'=>'3', '1'=>'4', '2'=>'5'];
$config = $this->configFactory->getEditable('bootstrap_horizontal_tabs.settings');
$config->set('version', $map[$form_state->getValue('version')])->save();
drupal_flush_all_caches();
parent::submitForm($form, $form_state);
}
}
Loading