Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Deprecation of $content.getLabelUtil()

Normann P_ Nielsen _Netic_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 27, 2019

My Macro:

 

## @noparams

<div id="related-content">

<script language=javascript>

function toogle(divname) {
if (document.getElementById(divname).style.display != "block") { document.getElementById(divname).style.display = "block"; }
else { document.getElementById(divname).style.display = "none"; }
}
</script>

#if($content.getIdAsString()!='4161541')
#set($wiki="")
#set($globalHelper=$action.getHelper())
#if($content) ## i. e. we render a normal page
#set($renderer=$globalHelper.getWikiStyleRenderer())
#set($context=$content.toPageContext())
#set($labelList=$content.getGlobalLabels($action.getRemoteUser()))
#if($labelList.size() > 0)
#set($labelUtil=$content.getLabelUtil())
#set($labels=$labelUtil.convertToDelimitedString($labelList))
#set($labels="'"+$labels+"'")
#set($labels=$labels.replace(" ","','"))
<h1><a href="javascript&colon;;" onclick="toogle('rcontent');">Sider med lignende indhold</a></h1>
<br>
<div id="rcontent" name="rcontent" style="display:block;">
<ac:structured-macro ac:macro-id="e5bbc54f-287e-447c-9e9e-f84af88ad353" ac:name="contentbylabel" ac:schema-version="2">
<ac:parameter ac:name="showLabels">false</ac:parameter>
<ac:parameter ac:name="cql">label in ($labels) AND label != "noshow"</ac:parameter>
</ac:structured-macro>
</div>
#end
#end
#end
</div>

 

Is not working in C7, seems $content.getLabelUtil() is deprecated.... https://confluence.atlassian.com/doc/deprecated-code-paths-removed-in-7-0-967879993.html

 

Ok, what do I do? Ad get whats possible with $content ? All I find is C6.6 related

1 answer

0 votes
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 28, 2019

Hello, @Normann P_ Nielsen _Netic_ !

I understand that is can be quite troubling when something is deprecated or completely removed from an array of tools that we are accustomed to using.

The content.getLabelUtil() method has been deprecated in a previous version of Confluence. Confluence 5.2, to be more precise. Here you can check this information:

 

Here is a screenshot of that page:

Anotação 2019-10-28 171136.jpg

 

According to the deprecation notice, we should start using LabelUtil directly. Here is a link to it:

 

If you need further assistance with developing questions, you can reach to our Developer Community, Normann. Here, take a look!

 

Let us hear from you!

Normann P_ Nielsen _Netic_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2019

As in: #set($labels=$content.LabelUtil().convertToDelimitedString($labelList)) ?

 

That does not work ...

Federico Vecchiarelli
Contributor
June 23, 2021

@Normann P_ Nielsen _Netic_were you able to figure out how to properly access the class LabelUtil?

Normann P_ Nielsen _Netic_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2021

@Federico Vecchiarelli 

 

Long time ago - my current code is:

 

## @noparams

<div id="related-content">

<script language=javascript>

function toogle(divname) {
if (document.getElementById(divname).style.display != "block") { document.getElementById(divname).style.display = "block"; }
else { document.getElementById(divname).style.display = "none"; }
}
</script>

#if($content.getIdAsString()!='4161541')
#set($wiki="")
#set($globalHelper=$action.getHelper())
#if($content) ## i. e. we render a normal page
#set($renderer=$globalHelper.getWikiStyleRenderer())
#set($context=$content.toPageContext())
#set($labelList=$content.getGlobalLabels($action.getRemoteUser()))
#if($labelList.size() > 0)
#set($labels="")
#foreach( $label in $labelList )
#if($labels == '')
#set($labels="'"+$label+"'")
#else
#set($labels=$labels+","+"'"+$label+"'")
#end
#end
#set($labels=$labels.replace(" ","','"))
<h1><a href="javascript&colon;;" onclick="toogle('rcontent');">Sider med lignende indhold</a></h1>
<br>
<div id="rcontent" name="rcontent" style="display:block;">
<ac:structured-macro ac:macro-id="e5bbc54f-287e-447c-9e9e-f84af88ad353" ac:name="contentbylabel" ac:schema-version="2">
<ac:parameter ac:name="showLabels">false</ac:parameter>
<ac:parameter ac:name="cql">label in ($labels) AND label != "noshow"</ac:parameter>
</ac:structured-macro>
</div>
#end
#end
#end
</div>

Federico Vecchiarelli
Contributor
June 23, 2021

Thanks @Normann P_ Nielsen _Netic_ . I was looking so hard at utilizing the actual method that totally overlooked the option to just iterate thru the list. What can I say, works for me!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events