View source
<?php
namespace Drupal\hidden_language\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\hidden_language\HiddenLanguageManager;
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class HiddenLanguageForm extends ConfigFormBase {
private $hiddenLanguageManager;
public function __construct(ConfigFactoryInterface $config_factory, HiddenLanguageManager $hiddenLanguageManagerService) {
parent::__construct($config_factory);
$this->hiddenLanguageManager = $hiddenLanguageManagerService;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('hidden_language.hidden_language_manager'));
}
public function getFormId() {
return 'hidden_language_settings';
}
protected function getEditableConfigNames() {
return [
'hidden_language.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['route_name'] = [
'#type' => 'textarea',
'#title' => $this
->t('Route name'),
'#description' => $this
->t('Enter the routes separated by ( , )'),
'#default_value' => implode(',', $this->hiddenLanguageManager
->getRoutesException()),
'#size' => 20,
'#required' => FALSE,
];
$form['path'] = [
'#type' => 'textarea',
'#title' => $this
->t('Path'),
'#description' => $this
->t('Enter the paths with ( / ) and separated by ( , )'),
'#default_value' => implode(',', $this->hiddenLanguageManager
->getPathsException()),
'#size' => 20,
'#required' => FALSE,
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('hidden_language.settings')
->set('route_name', $this->hiddenLanguageManager
->encodeArray($form_state
->getValue('route_name')))
->set('path', $this->hiddenLanguageManager
->encodeArray($form_state
->getValue('path')))
->save();
parent::submitForm($form, $form_state);
}
}