public static function countParents(View $v) { $current = $v->parent(); $count = 0; while (!is_null($current)) { $current = $current->parent(); $count++; } return $count; }