Is there a way to get an SObject (Tab) icon (name) to be referenced from the design system resource?
I'm building a custom visualforce page that will be displayed using Lightning, so I need to style it accordingly. My problem is that I really don't know what is the best practice to get the icon or at least it's name so I can reference the design system resource, here is an example:
I have a visualforce page with an icon as:
<span class="slds-icon_container slds-icon_container--circle slds-icon-action-description">
<svg aria-hidden="true" class="slds-icon slds-icon--small">
<use xlink:href="{!URLFOR($Resource.SLDS100,'assets/icons/custom-sprite/svg/symbols.svg#custom44')}"></use>
</svg>
</span>
And I need to do something like this:
<span class="slds-icon_container slds-icon_container--circle slds-icon-action-description">
<svg aria-hidden="true" class="slds-icon slds-icon--small">
<use xlink:href="{!URLFOR($Resource.SLDS100,iconName)}"></use>
</svg>
</span>
Where iconName
is the URL of the svg icon of the current standardController
object, right now I'm getting it from the extension like (not exactly):
public String getIconName(){
List<Schema.DescribeTabSetResult> tabSetDesc = Schema.describeTabs();
List<Schema.DescribeTabResult> tabDesc = new List<Schema.DescribeTabResult>();
List<Schema.DescribeIconResult> iconDesc = new List<Schema.DescribeIconResult>();
for(Schema.DescribeTabSetResult tsr : tabSetDesc) {
tabDesc.addAll(tsr.getTabs());
}
for(Schema.DescribeTabResult tr : tabDesc) {
if (tr.getSobjectName() == 'Custom__c') {
iconDesc.addAll(tr.getIcons());
}
}
String u;
for (Schema.DescribeIconResult ir : iconDesc) {
if (ir.getContentType() == 'image/svg+xml'){
u = ir.getUrl();
break;
}
}
Integer s = u.indexOf('/custom/') + '/custom/'.length(),
e = u.length() - 4;
return 'assets/icons/custom-sprite/svg/symbols.svg#' + u.substring(s, e);
}
But with lightning in mind, it really looks like there should be a better way to achieve this (without all those loops), and this workaround doesn't work for a custom icon.
Notes:
- Similar question
- This needs to work in a managed package, where the icon changes from org to org.