code: public @Nullable String getLinkRootPath(@NotNull Page page, @NotNull String linkTypeId) {
      if (StringUtils.equals(linkTypeId, InternalLinkType.ID)) {
        // inside an experience fragment it does not make sense to use a site root path
        if (Path.isExperienceFragmentPath(page.getPath())) {
          return DEFAULT_ROOT_PATH_CONTENT;
        }
        return AdaptTo.notNull(page.getContentResource(), SiteRoot.class).getRootPath(page);
      }
      else if (StringUtils.equals(linkTypeId, InternalCrossContextLinkType.ID)) {
        return DEFAULT_ROOT_PATH_CONTENT;
      }
      else if (StringUtils.equals(linkTypeId, MediaLinkType.ID)) {
        return DEFAULT_ROOT_PATH_MEDIA;
      }
      return null;
    }
docs: Get root path for picking links using path field widgets.
  @param page Context page
  @param linkTypeId Link type ID
  @return Root path or null