SharePoint 2010: RemoveFieldRef and Inherits="TRUE"

4.4k views Asked by At

I have created a custom content type that inherits from the OOTB SharePoint Picture content type. The only customisations I have made is to add a simple URL field, and remove two of the fields on the base type. See below:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Parent ContentType: Picture (0x010102) -->
    <ContentType ID="0x0101020027f16ab27e6e45a6848c25c47aaa7053"
                 Name="Custom Picture"
                 Description=""
                 Group="Custom"
                 Inherits="TRUE"
                 Version="0">
        <FieldRefs>
            <RemoveFieldRef ID="{b66e9b50-a28e-469b-b1a0-af0e45486874}" Name="Keywords" />
            <RemoveFieldRef ID="{a5d2f824-bc53-422e-87fd-765939d863a5}"  Name="ImageCreateDate" />
            <FieldRef ID="{c29e077d-f466-4d8e-8bbe-72b66c5f205c}" Name="URL" DisplayName="URL" Required="FALSE" />
        </FieldRefs>
    </ContentType>
</Elements>

If I create a picture library based on my custom content type, the "URL" field that I added appears in the new/edit forms, however the two fields that I have attempted to remove are also displayed, i.e. the RemoveFieldRef's are being ignored. If I look at the content type in "Site Settings -> Content Type Gallery", these two fields are still listed there.

Setting Inherits="FALSE" on my custom content type (see MSDN definition) successfully removes just these two fields from the "Site Settings -> Content Type Gallery" page, however then none of the base fields are displayed in the new/edit forms -- only my custom "URL" field.

What can I do to ensure that all the fields from the base "Picture" content type are displayed on the new/edit forms of my picture library except the two fields that I have specifically removed?

1

There are 1 answers

0
SpartanDonut On

I believe the nature of this issue to be the understanding of how content type inheritance works.

From MSDN (http://msdn.microsoft.com/en-us/library/aa544268.aspx)

If Inherits is TRUE, the child content type inherits all fields that are in the parent, >including fields that users have added.

If Inherits is FALSE or absent and the parent content type is a built-in type, the child >content type inherits only the fields that were in the parent content type when >SharePoint Foundation was installed. The child content type does not have any fields that >users have added to the parent content type.

If Inherits is FALSE or absent and the parent content type was provisioned by a sandboxed >solution, the child does not inherit any fields from the parent.

I think the key phrase above is "If Inherits is TRUE, the child content type inherits ALL fields that are in the parent including fields that users have added."

This means that in order to accomplish what you set out to do you will have inherits set to false and you will have to include FieldRef elements for all fields you wish to use in your content type.

You make no reference / don't include code for how the content type was added to your list instance. Make sure this has been updated to support the removal or setting of inherits to false.

These sites support what is described here.