fabi_s
July 23, 2021, 7:05am
1
Hello!
I want to get all tags from a node programmatically.
What is the correct way to do this?
There is ISystemTagObjectMapper::getTagIdsForObjects
. Do i have to use this function or is there a better way to get the tags for a node?
Thank you very much!
Fabian
fabi_s
July 26, 2021, 7:41am
2
Hello!
So here is my solution to the problem.
Using ISystemTagObjectMapper::getTagIdsForObjects
didn’t work for me so i wrote my on function using the IDBConnection
interface.
Here it is:
public function getSystemTagsForNode(int $nodeId): array {
$query = $this->connection->getQueryBuilder();
$query->select("*")
->from(SystemTagObjectMapper::RELATION_TABLE, "m")
->innerJoin("m", SystemTagManager::TAG_TABLE, "s", "m.systemtagid = s.id")
->where($query->expr()->eq('m.objectid', $query->createParameter('oId')))
->setParameter('oId', $nodeId);
$systemTagIds = [];
$result = $query->execute();
while ($row = $result->fetch()) {
$systemTag = $this->createSystemTagFromRow($row);
array_push($systemTagIds, $systemTag);
}
$result->closeCursor();
return $systemTagIds;
}
Regards
Fabian