What is Attachable really doing here?

Topics: Writing modules
Mar 29, 2012 at 1:59 PM

This code snippet from Sipke's tutorial (which is awesome, by the way) has me a little confused. In his tutorial, he says that .Attachable allows Content Parts to be added to Content Types. But in the code snippet, below a Content Part is declared as .Attachable(false) and is still being added to a Content Type. So there must be some other criteria that I'm not realizing. So what is really the difference between CustomerPart and the AddressPart, as far as Attachable is concerned?

            ContentDefinitionManager.AlterPartDefinition(typeof(Models.CustomerPart).Name, p => p
                .Attachable()
                );

            ContentDefinitionManager.AlterTypeDefinition("Customer", t => t
                .WithPart(typeof(Models.CustomerPart).Name)
                .WithPart("UserPart")
                );

            ContentDefinitionManager.AlterPartDefinition(typeof(Models.AddressPart).Name, p => p
                .Attachable(false)
                .WithField("Name", f => f.OfType(typeof(TextField).Name))
                .WithField("AddressLine1", f => f.OfType(typeof(TextField).Name))
                .WithField("AddressLine2", f => f.OfType(typeof(TextField).Name))
                .WithField("Zipcode", f => f.OfType(typeof(TextField).Name))
                .WithField("City", f => f.OfType(typeof(TextField).Name))
                .WithField("Country", f => f.OfType(typeof(TextField).Name))
                );

            ContentDefinitionManager.AlterTypeDefinition("Address", t => t
                .WithPart(typeof(Models.AddressPart).Name)
                );

Mar 29, 2012 at 2:23 PM

Attachable set to false means you wont be able to add the part to content type in the Admin. You still can do it through migration.