Using the menu API, how do I get only the enabled links? Using the code below I am able to get all the titles and links from the main menu, however, I only need the enabled ones. 
I have been searching for an answer for a couple of days but have been unable to find any.

$tree = \Drupal::menuTree()-&gt;load('main', new MenuTreeParameters());
foreach ($tree as $item) {
  $title = $item-&gt;link-&gt;getTitle();
  $url_object = $item-&gt;link-&gt;getUrlObject();
  array_push($menulinks, $title);
  array_push($urlformenulink, $url_object);
}


Please assist.
Set onlyEnabledLinks() on the menu tree parameters:

$parameters = new MenuTreeParameters();
$parameters-&gt;onlyEnabledLinks();
$tree = \Drupal::menuTree()-&gt;load('main', $parameters);