ConfigurationForm.php in Organic Groups Menu (OG Menu) 8
File
src/Form/ConfigurationForm.php
View source
<?php
namespace Drupal\og_menu\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class ConfigurationForm extends ConfigFormBase {
public function getFormId() {
return 'og_menu_configuration';
}
protected function getEditableConfigNames() {
return [
'og_menu.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this
->config('og_menu.settings');
$form['autocreate'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Automatically create new menus'),
'#description' => $this
->t('When enabled an OG Menu will automatically be created when new group is created.'),
'#default_value' => $config
->get('autocreate'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('og_menu.settings')
->set('autocreate', $form_state
->getValue('autocreate'))
->save();
}
}