Broken "Preview File" link in CM System 7.2

I was poking around in version CM System 7.2 today trying to implement Image previews in the content editor for a client, when I discover that my binary links no longer worked, and – Lo – neither did the built-in “Preview File” links for any other sys_File on their system.

It seems this stems from something Percussion (or perhaps PSO) folded into their activeEdit.xsl file to support contextual help.

Someone, and I’m not going to mention any names, seems to have implemented something without fully regression testing the rest of the system.

Anyway, The following code is the culprit:


	<xsl:template match="Control[ParamList/Param[@name='helptext']]" priority="25" mode="psxcontrol">
		<!-- Display normal control template without helptext -->
		<xsl:variable name="control-stripped-of-help">
			<xsl:apply-templates select="." mode="copy-all-but-help-param"/>
		</xsl:variable>
		<!-- 
				override all controls to display the "helptext" then return control to the standard template
		-->
		<xsl:apply-templates select="exsl:node-set($control-stripped-of-help)" mode="psxcontrol"/>
		<xsl:if test="ParamList/Param[@name='helptext']">
			<!-- define both variables -->
			<xsl:variable name="helptext" select="ParamList/Param[@name='helptext']"/>
			<!-- insert the helptext icon with the appropriate attributes -->
			<span class="helptext" tabindex="0">
				<img src="../sys_resources/images/helptext_icon.png" alt="{$helptext}" title="">
					<!-- only add the "title" attribute if the "helptext" param is defined -->
					<xsl:if test="$helptext">
						<xsl:attribute name="title"><xsl:value-of select="$helptext"/></xsl:attribute>
					</xsl:if>
				</img>
			</span>		
		</xsl:if>	
	</xsl:template>
	
	<!-- return control to dispatcher -->
	<xsl:template match="@* | node()" mode="copy-all-but-help-param">
		<xsl:copy>
			<xsl:apply-templates select="@* | node()" mode="copy-all-but-help-param"/>
		</xsl:copy>
	</xsl:template>
	
	<!-- suppress the helptext so the dispatch isn't recursive -->
	<xsl:template match="Param[@name='helptext']" mode="copy-all-but-help-param"/>

The reason this breaks the preview links is that the links require the full XML context to be present, and this code removes everything above the current control.

I found this offending code in
[ul]
[li]sys_resources/stylesheets/activeEdit.xsl
[/li][li]rx_resources/stylesheets/rx_Templates.xsl
[/li][li]rx_resources/stylesheets/controls/rx_TaxonomyAccordion.xsl
[/li][li]
[/li][/ul]

You can replace this with the following code instead:


	<xsl:template match="Control" mode="psxcontrol-helptext"></xsl:template>
	<xsl:template match="Control[ParamList/Param[@name='helptext']]" priority="25" mode="psxcontrol-helptext">
			<!-- define both variables -->
			<xsl:variable name="helptext" select="ParamList/Param[@name='helptext']"/>
			<!-- insert the helptext icon with the appropriate attributes -->
			<span class="helptext" tabindex="0">
				<img src="../sys_resources/images/helptext_icon.png" alt="{$helptext}" title="">
					<!-- only add the "title" attribute if the "helptext" param is defined -->
					<xsl:if test="$helptext">
						<xsl:attribute name="title"><xsl:value-of select="$helptext"/></xsl:attribute>
					</xsl:if>
				</img>
			</span>
	</xsl:template>

The ONLY place this is required is in activeEdit.xsl, and can be stripped from any other file.

Hope this helps! Good luck.

One last thing, any instance, in activeEdit.xsl, of:

<xsl:template select=“Control” mode=“psxcontrol”>

should be replaced with:

<xsl:template select=“Control” mode=“psxcontrol”>
<xsl:template select=“Control” mode=“psxcontrol-helptext”>

Also, I am fairly sure that this broken behavior only manifests for sys_File controls that also have helptext defined.

Thanks, Rushing, for posting about your findings. This kind of thorough explanation can be a lifesaver.