MenuItem(Part) odditity

Topics: Writing modules
Mar 4, 2011 at 12:40 PM
Edited Mar 4, 2011 at 12:41 PM

Currently the content type MenuItem is declared as a migration

ContentDefinitionManager.AlterTypeDefinition("MenuItem", cfg => cfg.WithPart("MenuPart"));

 

and being extended by a content handler inside the very same module which adds a MenuItemPart content part

Filters.Add(new ActivatingFilter<MenuItemPart>("MenuItem"));

 

Does this introduce any features which would not be possible by just declaring it at the migration level?:

ContentDefinitionManager.AlterTypeDefinition("MenuItem", cfg => cfg.WithPart("MenuPart").WithPart("MenuItemPart");
Coordinator
Mar 15, 2011 at 1:39 AM

Louis could confirm but I'm pretty sure that's a remnant from the time when we did not have content type metadata.

This being said, doing it in code opens up a whole lot of scenarios where a content type is enriched dynamically based on some condition over which you have complete power.

Apr 13, 2011 at 3:56 PM
Edited Apr 13, 2011 at 3:57 PM
bertrandleroy wrote:

Louis could confirm but I'm pretty sure that's a remnant from the time when we did not have content type metadata.

This being said, doing it in code opens up a whole lot of scenarios where a content type is enriched dynamically based on some condition over which you have complete power.

Does this mean that one should prefer using ActivatingFilter<>() calls over explicitly manipulating content types with AlterTypeDefinition()? Are there any advantages to altering the type definition? Any disadvantages to using ActivatingFilter<>()? It would be very insightful if you could spare a few words explaining the two approaches a bit more. Thanks!

Coordinator
Apr 13, 2011 at 6:10 PM

Not in general, no. This is just the difference between declarative and procedural. Declarative is easy and convenient but implies one-time definition whereas with code you can add some arbitrary flexibility (applying conditions, etc.). In general though the declarative approach in a migration is just fine and just what you need.