SharePoint 2010: RemoveFieldRef and Inherits="TRUE"
Asked Answered
K

1

7

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?

Kruller answered 23/2, 2011 at 11:40 Comment(2)
Try two things: 1. Removing Inherits or 2. Setting Inherits=False and just referencing the fields you want from the parent to your content type e.g. ´<FieldRef ID=...`Genome
Removing the inheritance is more of a workaround than a solution to the RemoveFieldRef problem. Similarly, I figured out that I can leave Inherits="TRUE" and just set the unwanted fields to Hidden="TRUE". However if I was using a content type with dozens of fields this might not be so tempting. So still looking...Kruller
C
1

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.

Colbycolbye answered 23/1, 2012 at 20:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.