Convert hook_menu in drupal 8 I have a hook_menu as follows :

/**
 * Implementation of hook_menu().
 */
function conditional_fields_menu() {
  $items = array();

  foreach (node_get_types() as $type) {
    $content_type = content_types($type-&gt;type);

    $items['admin/content/node-type/' . $content_type['url_str'] . '/conditional'] = array(
      'title' =&gt; 'Conditional fields',
      'page callback' =&gt; 'drupal_get_form',
      'page arguments' =&gt; array('_conditional_fields_admin', $content_type['type']),
      'access arguments' =&gt; array('administer conditional fields'),
      'type' =&gt; MENU_LOCAL_TASK,
      'weight' =&gt; 5
      );
  }

  return $items;
}


How can i convert this to conditional_fields.routing.yml in d8 ?

what i tried :

Drupal 8 conditional_fields.routing.yml snippet

conditional_fields.admin:
  path: 'admin/content/node-type/{this is unknown}/conditional'
  defaults:
    _form: '_conditional_fields_admin'
    _title: 'Conditional fields'
  requirements:
    _permission: 'administer conditional fields'
The routing system uses pattern matching. You can define a parameter in the path that will be used as a variable. 

If we look at this snippet of node.routing.yml:

node.add:
  path: '/node/add/{node_type}'
  defaults:
    _controller: '\Drupal\node\Controller\NodeController::add'
    _title_callback: '\Drupal\node\Controller\NodeController::addPageTitle'
  requirements:
    _node_add_access: 'node:{node_type}'
  options:
    _node_operation_route: TRUE
    parameters:
      node_type:
        with_config_overrides: TRUE


You can see the {node_type} in the path. This variable will contain the node type as specified in the path. You can use that as part of the requirement as you can see above, and it will also be available to your functions. \Drupal\node\Controller\NodeController::add receives the node_type variable as well:

public function add(NodeTypeInterface $node_type) {
  $node = $this-&gt;entityManager()-&gt;getStorage('node')-&gt;create(array(
    'type' =&gt; $node_type-&gt;id(),
  ));

  $form = $this-&gt;entityFormBuilder()-&gt;getForm($node);

  return $form;
}


Read Parameters in routes for more information.

And for forms:

example.user_form
  path: 'example/form/{user}'
  defaults:
    _form: '\Drupal\example\Form\ExampleForm'
  requirements:
    _permission: 'access content'


You can use the buildForm function and place the additional parameters after $form and $form_state.

namespace Drupal\example\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Session\AccountInterface;

class BasicForm extends FormBase {

 public function buildForm(array $form, FormStateInterface $form_state, AccountInterface $user = NULL) {
    // Do something with $user in the form
  }
}