Drupal 10: Using A Lazy Builder To Create A Dynamic Button
… the ajax callback. $build['lazy_button'] = [ '#type' => 'link', '#url' => Url::fromRoute('lazy_button_callback'), '#title' => $buttonText, … when a user clicks on this link it should initiate an ajax call to the URL. In this case we are passing in the route "lazy_button_callback", …