I have URLs defined in links.menu.yml file as "route_parameters: {webform: 'abc'}", but I need to update webform value based on the page URL. If URL has "/type1/" in it, keep webform: 'abc' OR If URL has "/type2/" in it, change the webform to webform: 'xyz'

please suggest.


1 Answer 1


so need to have a hook_form_alter
then if this is the webform id you need see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/function/Url%3A%3AgetRouteParameters/9.2.x

 * Implements hook_form_alter().
function YOURMODUE_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form_id === 'XXX') {
    $prams = Drupal\Core\Url::getRouteParameters();
    if (!empty($prams)) {
      // set the value of the field here/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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