9

I'm wondering if there is a clever or preferred way of using Display Suite to display one of two fields.

So my case calls for either an image, if it is uploaded, or a EVA (entity views attachment). I have them both displaying correctly, and of course if the image is not uploaded (unpopulated), then the EVA field displays fine. But if the image is uploaded, I want to hide the EVA field.

I guess I could do a custom code field, but I would like to avoid that if there is a built-in method of choosing one over another field. Maybe something with field groups?

Thanks!

3 Answers 3

2

Your only option is a custom code field. There have been attempts to make conditional fields possible through the UI, but it was too complex.

1
  • 1
    That would probably be a fine solution, but I wouldn't call it the only option. I'm sure you can also hide the EVA from a preprocess function, or even configure the EVA view so it doesn't return anything if an image is present. Commented Oct 18, 2011 at 5:50
4

Use the field formatter conditions module: https://www.drupal.org/project/ffc

This will give you the same options that you have on a blocks (and more). So you can show the field based on any url pattern just as you would blocks:

http://cl.ly/image/2A2Y373Y3e1J

Hope this help.

1

You can use Renderkit with Entity Display Plugin for Field UI for problems like this.

I have not tried it with EVA specifically, but it can embed views displays, among other things.

The integration of the drilldown form into the field UI form is currently a bit clunky, but it works.

I recommend to also enable Cfr Preset.

Preparation:

  • Enable entdispfieldui
  • Optionally enable cfrpreset

On the "Manage display" page:

  • Scroll to the bottom, add an EntDisP field.
  • Move the field up into an active Region.
  • Click "Save" at the bottom of the page.
  • Edit the configuration for the EntDisP field (click the cog-wheel).
  • Choose "Chain of responsibility", then "Field with formatter" or "Image with processor".
  • Click "Update" on the sub-form.
  • Click the cog-wheel again to open the form again.
  • Choose "Views display.." for "New item". Choose the views display id.
  • Click "Update" on the sub-form.
  • Click "Save" at the bottom of the page.

It should work now, but having this configuration within the display configuration is messy.

To avoid this, you can use cfrpreset.

On the "Manage display" page:

  • Click the cog-wheel again.
  • Mouse-hover next to the drilldown select element for "Entity display".
  • Click "Create a preset" (opens in new tab).

On the "Add preset" page:

  • Choose a name for the preset.
  • Save.

On the "Manage display" page:

  • Close the sub-form, if it is still open.
  • Click the cog-wheel again.
  • Choose the preset you just created.
  • Click "Update" on the sub-form.
  • Click "Save" at the bottom of the page.

Optionally, you can export partial configuration as new presets.

Screenshots

I hope these are not too much. Would be great to have an expand/collapse thingie.

Add EntDisP field.

Add an EntDisP field.

Configuration with "Field with formatter".

Configure the EntDisP field.

Alternative configuration with "Image with processor".

Alternative configuration using "Image with processor".

Export as preset.

Optionally, export as a preset.

Save the preset.

Save the preset.

Use the preset instead of the in-place configuration.

Use the preset instead of in-place configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.