Create Context Based on Field File Type I want a means of triggering a different Context depending on the type of file used in a field on a given content type.

I have been struggling with trying to achieve this for a few days/weeks now after recently moving from D6 to D7. After trying it with Panels I've moved onto Context Module and Context Entity Field. I'm hoping I can finally get this sorted so all help appreciated thanks.

I don't know if it's my lack of D7 experience that's causing this. Basically, I'm working with one content type. It has a Multimedia asset field. I allow uploading, adding images and youtube media via url in this field. I was wanting to create a new page context if the field contains youtube video field. If it has an image then let's do another context etc. Only one of these filetypes are allowed per node.

Context Entity Field seems to only work if the Multimedia asset field has something, or not. I was wanting to use context on file type.

Is this possible or am I really missing some simple D7 point that wasn't there in D6?

Thanks

Note that I am using Media Module for this Multimedia asset field.
Can I suggest a slightly different strategy? If you have the Rules modules installed - or are willing to install it - then can use a Rules condition to apply the specific test you want. If it passes that test, you can get Rules to set a field on your node that Context can respond to.

So, for example, you could have a Term reference on your content type that has three vocabulary items 'YouTube', 'Image', 'Empty'. Rules can set this field whenever the node is saved. And Context is able to respond differently depending on the Taxonomy Term that is present.

A downside is the user gets to see the Term reference field when entering data, but since it's changed to the right value on save anyway, this may not be a big deal. You can tell the user to ignore this on the form and hide it away, e.g. in a closed fieldset. Or if you are a Display Suite user, you can easily hide using configuration.

I've tested whether Rules can pick up the media type and can confirm it does so quite cheerfully. To start the process, add a new rule and choose React on event with the type 'Before saving content'. Supposing you have a field on your content type with the machine name field_media, then you will need to use a Data comparison condition that checked [node:field-media:file:mime] to see if it is equal to video/youtube or image\png etc. You may need to do a bit of fishing to get out all the relevant mime types. You'll then need to create an appropriate action when the condition is true. You'll probably want several rules bundled together in a Rule set.

A single condition will look a bit like this:



If you've not used Rules before, it can be a bit fiddly to set up the first couple of times, but well worth it. Knowing that it can detect the condition that is of interest to you, means that this is a solution that you can make work.