X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdevel%2Fsrc%2FForm%2FToolbarSettingsForm.php;fp=web%2Fmodules%2Fcontrib%2Fdevel%2Fsrc%2FForm%2FToolbarSettingsForm.php;h=d0e09fc7ed320436c9b2c95b947561d0b2aabf34;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/devel/src/Form/ToolbarSettingsForm.php b/web/modules/contrib/devel/src/Form/ToolbarSettingsForm.php new file mode 100644 index 000000000..d0e09fc7e --- /dev/null +++ b/web/modules/contrib/devel/src/Form/ToolbarSettingsForm.php @@ -0,0 +1,118 @@ +menuLinkTree = $menu_link_tree; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('menu.link_tree') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'devel_toolbar_settings_form'; + } + + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return [ + 'devel.toolbar.settings', + ]; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state) { + $config = $this->config('devel.toolbar.settings'); + + $form['toolbar_items'] = [ + '#type' => 'checkboxes', + '#title' => $this->t('Menu items always visible'), + '#options' => $this->getLinkLabels(), + '#default_value' => $config->get('toolbar_items') ?: [], + '#required' => TRUE, + '#description' => $this->t('Select the menu items always visible in devel toolbar tray. All the items not selected in this list will be visible only when the toolbar orientation is vertical.'), + ]; + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $values = $form_state->getValues(); + $toolbar_items = array_keys(array_filter($values['toolbar_items'])); + + $this->config('devel.toolbar.settings') + ->set('toolbar_items', $toolbar_items) + ->save(); + + parent::submitForm($form, $form_state); + } + + /** + * Provides an array of available menu items. + * + * @return array + * Associative array of devel menu item labels keyed by plugin ID. + */ + protected function getLinkLabels() { + $options = []; + + $parameters = new MenuTreeParameters(); + $parameters->onlyEnabledLinks()->setTopLevelOnly(); + $tree = $this->menuLinkTree->load('devel', $parameters); + + foreach ($tree as $element) { + $link = $element->link; + $options[$link->getPluginId()] = $link->getTitle(); + } + + asort($options); + + return $options; + } + +}