Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tridion core service: How to check if multi line field has rich text formatting enabled?

I want to check through core service if rich text formatting is enabled on a multi line field or not.

If I analyze source of a schema after rich text format enabling then there are lots of tags inserted for this purpose:-

  <tcm:Size xmlns:tcm="http://www.tridion.com/ContentManager/5.0">2</tcm:Size>
          <tcm:FilterXSLT xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
              <xsl:output omit-xml-declaration="yes" method="xml" cdata-section-elements="script"></xsl:output>
              <xsl:template name="FormattingFeatures">
                <FormattingFeatures xmlns="http://www.tridion.com/ContentManager/5.2/FormatArea">
                  <Doctype>Transitional</Doctype>
                  <AccessibilityLevel>0</AccessibilityLevel>
                  <DisallowedActions></DisallowedActions>
                  <DisallowedStyles></DisallowedStyles>
                </FormattingFeatures>
              </xsl:template>
              <xsl:template match="/ | node() | @*">
                <xsl:copy>
                  <xsl:apply-templates select="node() | @*"></xsl:apply-templates>
                </xsl:copy>
              </xsl:template>
              <xsl:template match="/body[not(processing-instruction() or comment() or normalize-space(translate(., &apos; &apos;, &apos;&apos;)) != &apos;&apos; or       *[@* or * or comment() or processing-instruction() or not(self::p or self::br)])]">
                <!-- make an empty <body> if all the body has is empty paragraphs, line-breaks and (non-breaking) spaces -->
                <xsl:copy></xsl:copy>
              </xsl:template>
              <xsl:template match="p[not(@* or * or comment() or processing-instruction() or normalize-space(translate(., &apos; &apos;, &apos;&apos;)) != &apos;&apos; or       following-sibling::node()[@* or * or comment() or processing-instruction() or not(self::p or self::text()) or normalize-space(translate(., &apos; &apos;, &apos;&apos;)) != &apos;&apos;])]">
                <!-- ignore all paragraphs at the end that have nothing but (non-breaking) spaces -->
              </xsl:template>
            </xsl:stylesheet>
          </tcm:FilterXSLT>

But which exactly is the property to find if rich text is enabled I am not able to figure out even in core service API document.

My core service code is a bit like below:-

SessionAwareCoreService2010Client client = new SessionAwareCoreService2010Client();
client.ClientCredentials.Windows.ClientCredential.UserName = "myUserName"; 
client.ClientCredentials.Windows.ClientCredential.Password = "myPassword";
client.Open();
SchemaFieldsData fields = client.ReadSchemaFields("tcm-x-y-z",
                                                  true, new ReadOptions());


foreach (var field in fields.Fields)
{
    if (field is MultiLineTextFieldDefinitionData)
    {
        return Constants.DataType.STRING;
    }
}

Please suggest.

like image 258
SDL Developer Avatar asked Dec 21 '22 14:12

SDL Developer


2 Answers

Just change your "is" check to compare with XhtmlFieldDefinitionData instead:

if (field is XhtmlFieldDefinitionData)
{
   ...
}
like image 66
Peter Kjaer Avatar answered May 10 '23 14:05

Peter Kjaer


You can use standard GetType().Name:

var schemaFields = ClientAdmin.ReadSchemaFields("tcm:2-82-8", false, new ReadOptions());
var field = schemaFields.Fields.First();
Assert.AreEqual("XhtmlFieldDefinitionData", field.GetType().Name);
like image 23
Andrey Marchuk Avatar answered May 10 '23 15:05

Andrey Marchuk