how do I get the depth of a MenuLinkContent?
Here is our approach:

$menu_link = $variables['element']['#original_link'];

$depth = 0;
$parent = $menu_link-&gt;getParent();
if ($parent) {
  while ($parent) {
    $parent_parts = explode(':', $parent);

    $parent_entity = \Drupal::service('entity.repository')-&gt;loadEntityByUuid($parent_parts[0], $parent_parts[1]);
    $parent = $parent_entity-&gt;get('parent')-&gt;get(0)-&gt;value;
    $depth ++;
  }
}


Hope to help