MenuPositionSettings.php in Menu Position 8
File
src/Form/MenuPositionSettings.php
View source
<?php
namespace Drupal\menu_position\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteBuilderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MenuPositionSettings extends ConfigFormBase {
protected $route_builder;
public function __construct(ConfigFactoryInterface $config_factory, RouteBuilderInterface $route_builder) {
parent::__construct($config_factory);
$this->route_builder = $route_builder;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('router.builder'));
}
protected function getEditableConfigNames() {
return [
'menu_position.settings',
];
}
public function getFormId() {
return 'menu_position_settings';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('menu_position.settings');
$form = [];
$form['menu_position_active_link_display'] = [
'#type' => 'radios',
'#title' => $this
->t('When a menu position rule matches:'),
'#options' => [
'parent' => $this
->t('Mark the rule\'s parent menu item as being "active".'),
'child' => $this
->t("Insert the current page's title into the menu tree."),
'none' => $this
->t('Don\'t mark any menu item as being "active".'),
],
'#default_value' => $config
->get('link_display'),
'#description' => $this
->t("By default, a matching menu position rule will mark the rule's parent menu item as active."),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('menu_position.settings')
->set('link_display', $form_state
->getValue('menu_position_active_link_display'))
->save();
$this->route_builder
->rebuild();
parent::submitForm($form, $form_state);
}
}