SettingsForm.php in Sub-pathauto (Sub-path URL Aliases) 8
File
src/Form/SettingsForm.php
View source
<?php
namespace Drupal\subpathauto\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Menu\MenuTreeStorage;
class SettingsForm extends ConfigFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('subpathauto.settings');
$form['depth'] = [
'#type' => 'select',
'#title' => $this
->t('Maximum depth of sub-paths to alias'),
'#options' => array_merge([
0 => $this
->t('Disabled'),
], range(1, MenuTreeStorage::MAX_DEPTH - 1)),
'#default_value' => $config
->get('depth'),
'#description' => $this
->t('Increasing this value may decrease performance.'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$this
->config('subpathauto.settings')
->set('depth', $values['depth'])
->save();
parent::submitForm($form, $form_state);
}
public function getFormId() {
return 'subpathauto_settings_form';
}
public function getEditableConfigNames() {
return [
'subpathauto.settings',
];
}
}