[Solved] Overriding Fields from a Module with Placement.info

Topics: Customizing Orchard, Troubleshooting
May 9, 2012 at 3:47 PM

Hello,

I have a module that creates a Content Type via it's Migration.cs. During the Migration one of my Content Parts gets a MediaPicker field attached to it:

            ContentDefinitionManager.AlterPartDefinition("SomePart", config => config
                .Attachable()
                .WithField("Image",
                    fieldBuilder => fieldBuilder
                        .OfType("MediaPickerField")
                        .WithDisplayName("Your Image")));

Now, I wish to suppress the default output of the MediaPicker field which would show "Your Image: ~/Path/to/Image.jpg" In my Placement.info file I have:

<Placement>
   ...
  <Place Fields_MediaPicker="-"/>
   ...
</Placement>

When I go to view the object the MediaPicker output is still shown. (Even giving it more specific name such as "Fields-MediaPicker-Image" or doing a Match on the ContentType seems to fail.)

However, if I go ahead and add the same Placement line to a Theme it does result in the MediaPicker field being hidden. However, adding it to the Placement.info file in the module doesn't seem to do the trick. (Other items in the Placement file related to my parts are working fine.)

Am I missing something special when it comes to the relationship of Module vs Module Placement.info conditions? (Could Ochard.Fields's Placement.info be overriding my Modules? And if so why would it do it for Specific cases such as Fields_MediaPicker-Image or Fields_MediaPicker-Type-Image?)

I am currently running Orchard 1.4.0.

Coordinator
May 9, 2012 at 5:51 PM

Fields_MediaPicker-Image or Fields_MediaPicker is the correct syntax (I'm using it on one of my sites). So I'd guess your placement.info is not getting picked up for some reason. You could verify that by making another obvious modification in the file. Oh wait, I just read the rest of your post. Yes, of course. You can not override something from another module, from your module. You either need to change that module or do it in the theme.

Just do it in the theme.

Coordinator
May 9, 2012 at 5:54 PM

I am sure it's taken into consideration, but the precedence order of placement.info files might be incorrect. What if all modules where defining it ? Which one to take. The solution is to delacre a dependency on Orchard.Fields from your modules. Then the placement will be executed after the other ones, and do the job.

May 9, 2012 at 6:05 PM

@bertrandleroy - Doing it in the theme does not make sense since this is a module that may be deployed to the Gallery. (I wouldn't want to have to instruct the user to update their theme after they install the module.

@sebastienros - Thank you. The missing dependency was where I faulted. With that in place the overrides are happening correctly.

Thank you both for your time and assistance!

Nov 7, 2013 at 11:16 PM
Wow I just had this issue as well and solved it by defining a dependency on Orchard.Fields as well. That's pretty subtle...or did is that documented somewhere and I just missed it?
Jan 31, 2014 at 11:50 AM
@sebastienros - Thank you so much for your solution.