Score:0

Update menu links based on the site URL

us flag

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.

4uk4 avatar
cn flag
Use the method getRouteParameters() in a menu link plugin. See for example this tutorial https://www.axelerant.com/blog/adding-dynamic-values-menu-links-drupal
Score:0
cn flag

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)) {
      dump($prams);
      // set the value of the field here/
    }
  }
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.