Hi!
You can use an EntityTitleLookup to get the Title object for an EntityId. In case of a Form, it will point to the appropriate section. You can use the
OK, I see it's just adding form id as a fragment, so it's easy I guess.
LinkRenderer service to make a link. Or you use an EntityIdHtmlLinkFormatter, which should do the right thing. You can get one from a OutputFormatValueFormatterFactory.
I can reimplement it manually, but I would be largely duplicating what HtmlPageLinkRendererBeginHookHandler is supposed to do. The problem seems to be that it is not doing it right. When the code works on the link like /wiki/Lexeme:L2#L2-F1, it does this:
$entityId = $foreignEntityId ?: $this->entityIdLookup->getEntityIdForTitle( $target );
Which produces back LexemeId instead of Form ID. It can't return Lexeme ID since lexeme does not have content model, and getEntityIdForTitle uses content model to get from Title to ID. So, I could duplicate all this code but I don't particularly like it. Could we fix HtmlPageLinkRendererBeginHookHandler instead maybe?