In the D7 version of this module menu items were created based on the path and the configuration of the config page
http://screencast.com/t/EUYOoRQBfaSe

This way I could see the link to configure the frontpage on the admin toolbar.

In D8 I don't know how to do this.
I'll try a mymodule.links.menu.yml

CommentFileSizeAuthor
#3 menu-links-2791581-1.patch1.52 KBicurk
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rodrigoaguilera created an issue. See original summary.

shumer’s picture

Assigned: Unassigned » shumer
icurk’s picture

Status: Active » Needs review
FileSize
1.52 KB

Here is a patch, which creates menu links.

boshtian’s picture

I confirm that this patch works for me.

boshtian’s picture

Status: Needs review » Reviewed & tested by the community

  • shumer committed 636274e on 8.x-1.x authored by icurk
    Issue #2791581 by icurk: Ability to create a menu item with the config...
shumer’s picture

Thx for this patch, already committed to dev version, so will be available with new release.

rodrigoaguilera’s picture

Status: Reviewed & tested by the community » Needs work

I found a little nitpick for this feature.
If I set the path to
/admin/config/system/general_configuration

Everything is OK

But /admin/config/system/general-configuration

fails to create the link.

Can we address this here?

rodrigoaguilera’s picture

I think I was confused by my debugging sorry.

what made the link disappear is using "drush cr". Does not matter if the path contains "_" or "-".

I think using hook_menu_links_discovered_alter to add new links is a bit weird. I think the implmentation of this functionality should be closer to what views does starting with the MODULE_NAME.links.menu.yml

Also using t($variable) should be fixed.

icurk’s picture

Strange... The issue is not with how the link is created, it has to do it with how you clear cache. If you run drush cr, then hook_menu_links_discovered_alter is not called, hence menu link is not created. But if you clear cache inside an administration, then this hook is called and menu link is created.

hook_menu_links_discovered_alter is the right way to do it, as this is one of the options written in drupal documentation "How to add dynamic menu links". And the other one is, as you said, with using deriver class in *.links.menu.yml file. I tested both options, but if you rebuild cache with drush menu links are not created.

rodrigoaguilera’s picture

You mean that you tried a deriver class and suffers from the same problem?
I tried to reproduce this with the menu links that views creates and I was no able to reproduce it so clearly config pages does something different.

Thanks for taking the time to look at it :)

  • shumer committed 636274e on 8.x-2.x authored by icurk
    Issue #2791581 by icurk: Ability to create a menu item with the config...
Grimreaper’s picture

Hello,

I have the same problem. The menu links are not created. The parent is not detected.

I confirm that when using drush cr, the hook_menu_links_discovered_alter is triggered

On the line:

$route = \Drupal::service('path.validator')->getUrlIfValid($path);

When in the execution of "drush cr", no route is found, but when executing using devel/php, it founds the right route.

rodrigoaguilera’s picture

I still feel is a problem with drush so if anyone can produce a test case for them to help fix this bug that would be great

https://github.com/drush-ops/drush/issues/2683#issuecomment-311626273

shumer’s picture

I can't reproduce this issue in my local environment. @Grimreaper or @rodrigoaguilera anyone of you still able to reproduce it? If so, please share STR with me. Thx.

shumer’s picture

Status: Needs work » Postponed (maintainer needs more info)
shumer’s picture

Status: Postponed (maintainer needs more info) » Needs work

  • shumer committed 9434ce1 on 8.x-2.x
    Issue #2791581 by icurk, shumer: Ability to create a menu item with the...
shumer’s picture

Status: Needs work » Fixed

Fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

flocondetoile’s picture

I found a bug related to this commit.

If you create a custom path, let's say /admin/config/cerema/activites, for a config page, then if you flush routing and links cache (with the custom link provided by admin_toolbar_tools), you've got a fatal error.

Le site Web a rencontré une erreur inattendue. Veuillez essayer de nouveau plus tard.</br></br><em class="placeholder">Symfony\Component\Routing\Exception\ResourceNotFoundException</em>: No routes found for &quot;/admin/flush/menu&quot;. in <em class="placeholder">Drupal\Core\Routing\Router-&gt;matchRequest()</em> (line <em class="placeholder">159</em> of <em class="placeholder">core/lib/Drupal/Core/Routing/Router.php</em>). <pre class="backtrace">Drupal\Core\Routing\Router-&gt;match(&#039;/admin/config/cerema&#039;) (Line: 162)
config_pages_get_route_name_from_path(&#039;/admin/config/cerema&#039;) (Line: 150)
config_pages_find_parent_route_name(&#039;/admin/config/cerema/activites&#039;) (Line: 126)
config_pages_menu_links_discovered_alter(Array, NULL, NULL) (Line: 501)
Drupal\Core\Extension\ModuleHandler-&gt;alter(&#039;menu_links_discovered&#039;, Array) (Line: 167)
Drupal\Core\Menu\MenuLinkManager-&gt;getDefinitions() (Line: 190)
Drupal\Core\Menu\MenuLinkManager-&gt;rebuild() (Line: 129)
Drupal\admin_toolbar_tools\Controller\ToolbarController-&gt;flush_menu()
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 576)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 153)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
</pre>

Because the parent /admin/config/cerema/ do not correspond to any existing routes.

As a workaround I added a custom route which correspond to the parent path.

Should we reopen this issue or create a new one ?

icurk’s picture

I think that it would be better to create a new issue.

rodrigoaguilera’s picture

Just FYI I do not suffer from the drush cr bug anymore with config pages 2.1 and drush 9