I’m working on a glossar feature:
I’ve special GlossarPages that hold the Glossar entries (Headline, description, image).
It works more or less. A Link to a GlossarPage within a normal inline editable Text brings up a small css popup on mouseover.
I grab the link using pregMatch().
In the Backend href=“node:// …”.
In the Frontend, there is the normal uri in the href attribute.
As a work around I use the Link-Text between the opening and closing tags to search in the GlossarPages (instanceOf) title property.
So, if the link text and the title text are differen it fails.
How can I get the node identifier in frontend and in backend mode out of the href attribute?
To get more than one link out of the text I’ve implemented an Eel-Helper with pregMatchAll().
Works fine, but than??
There is no loop or “each in Fusion”. If I could handle 10 Glossar entries in a text, that would be sufficient for me.
Do I really have to write 10 Cases, one after the other, or is there some “more elegant” way?
Do it partly in Fluid?
Is there another possibility to insert HTML-Snippets using aloha?
It still is a good idea to do actually convert those links only in the frontend. Because in the backend you want to be able to click on a linked item and edit the text. You can look at the code of convertUris as reference for that.
I like your proposal Martin.
This way one can implement even more special processings for different link types in a consistent manner.
I started to go that way but get stucked again (in the PHP code):
There are so many factories, interfaces, contexts, workspaces, dimensions, runtime …
I saw some posts (from Martin and Dominique) and tried this or that.
In most of the cases I just get a “500” with a white page.
I already got the node identifiers of the links within the text.
For each identifier I want to:
Get a node using the node id (got null).
Check if it is of type GlossaryPage.
If true: get the properties of that node.
Build the markup for the CSS popup
Replace the old link with the markup.
Add a cache tag for every GlossaryPage link found to the cache of the Text content element.
(Cound be also a tag like NodeType_GlossaryPage)
4. Use flow Query to find a node for a given id in a site
// the flow query context is always an array
$flowQuery = new FlowQuery([$site]);
$targetNode = $flowQuery->find('#' + $nodeIdentifier)->get(0);
5. Check for the type of the target
if ($targetNode instanceof NodeInterface &&
$targetNode->getNodeType()->getName() === 'Vendor.Site:GlossaryItem'
// here happens magic
Hint: You will have to add use statements for the full namespaces for FlowQuery and NodeInterface but in general this should do the trick. As usual beware of typos. This is untested code but i’ve done that several time that way.