3

Here is the code in mymodule.links.action.yml to add a local action in a custom page (generated by the Views module).

amidori_utils.add_content:
  route_name: 'node.add_page'
  title: 'Add Content'
  appears_on:
    - view.admin_blogs.page_1

The above page will create a local action menu, which will take you to node/add page which will again list links to various content that you can create.

What I want is to create a link to node/add/blog as a local action. How can I do it?

After watching to the content of the node.routing.yml file, I understand I need to use node.add as route, but I can't figure out how to pass blog as parameter to the end of the route.

1
  • Search for the local action manager class, there you can look for the possible parameters that you can provide in the YAML.
    – Eyal
    Nov 18 '16 at 22:54
7

Basing on this comment found on Local action links now provided by plugins using YAML discovery and implementing LocalActionInterface, this is the action declaration you should use.

amidori_utils.add_content:
  route_name: 'node.add'
  title: 'Add content'
  route_parameters:
    node_type: 'blog'
  appears_on:
      - view.admin_blogs.page_1

I take that, in your case, node_type should be simply blog, if that is the machine name for the content type you want to let users create.

1
  • Just want to document out loud: I had a bit of a time trying to find how to add a link to a Media (in core) bundle "Playlist" created in-house. The following worked: route_name: 'entity.media.add_form' title: 'Add Playlist' route_parameters: media_type: 'playlist' appears_on: - ... Jul 29 '19 at 21:04
0
 route_name: node.add
 route_parameters:
   node_type: 'blog' 

This will show node/add/blog.

2
  • 2
    Please add some more details to explain "this", that will prevent your answer will be perceived as low quality answer, which puts it at risk of being deleted via moderation ... Nov 19 '16 at 9:33
  • thanks for the pointer, @Nguyen Quoc. Your tip does help in solving the answer. However, i have to accept kiamlaluno's answer since it will help more people in the future.
    – D34dman
    Nov 19 '16 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.