Rebase + adapt fix for 7385

This commit is contained in:
jf-cbd
2026-08-14 10:28:06 +02:00
parent ac9d9934d5
commit d2445f3d17

View File

@@ -3036,24 +3036,36 @@ TXT
public static function GetMentionedObjectsFromText(string $sText): array
{
$aMentionedObjects = [];
$aMentionAllowedClasses = MetaModel::GetConfig()->Get('mentions.allowed_classes');
$oDom = new \DOMDocument();
libxml_use_internal_errors(true); // to keep processing even in case of "invalid" HTML, cf. testGetMentionedObjectsFromText
$oDom->loadHTML($sText);
$oDom->loadHTML('<?xml encoding="UTF-8">'.$sText);
$oXpath = new \DOMXPath($oDom);
$oNodes = $oXpath->query('//a[@data-object-class and @data-object-key]');
foreach ($oNodes as $oObjNode) {
$sObjClass = $oObjNode->getAttribute('data-object-class');
$sObjId = $oObjNode->getAttribute('data-object-key');
$sMatchedClass = $oObjNode->getAttribute('data-object-class');
$sMatchedId = $oObjNode->getAttribute('data-object-key');
$sMatchedName = trim($oObjNode->textContent);
$sMentionPrefix = array_search($sMatchedClass, $aMentionAllowedClasses); // for N°7385
if ($sMentionPrefix === false) {
continue;
}
// Test if the visible mention starts with the expected configured marker.
if (str_starts_with($sMatchedName, $sMentionPrefix) === false) {
continue;
}
// Prepare array for matched class if not already present
if (!array_key_exists($sObjClass, $aMentionedObjects)) {
$aMentionedObjects[$sObjClass] = [];
if (!array_key_exists($sMatchedClass, $aMentionedObjects)) {
$aMentionedObjects[$sMatchedClass] = [];
}
// Add matched ID if not already there
if (!in_array($sObjId, $aMentionedObjects[$sObjClass])) {
$aMentionedObjects[$sObjClass][] = $sObjId;
if (!in_array($sMatchedId, $aMentionedObjects[$sMatchedClass])) {
$aMentionedObjects[$sMatchedClass][] = $sMatchedId;
}
}