Use case: you have a video and image field. If there's a video uploaded, do not show the image field.
Whether this might be a new sort field at admin/structure/ds/fields or someting in the UI is not decided yet.

Comments

muka’s picture

swentel’s picture

Hrm, that's probably a good idea (haven't been able to look further on that issue, been swamped with other work right now), I'll think about it (or in case you have patches, feel free. This could all go into the ds_context module which I'll try to review soon!

swentel’s picture

Status: Active » Fixed

This is committed. It's a a field which acts as a 'group' where you nest children underneath. The logic is simple (and covers 95% of the use cases we have all the time): the first item with is rendered, the rest is ignored. We might extend this later on with other simple use cases, but for now this is good enough.

swentel’s picture

Status: Fixed » Needs work

Setting back to needs work, it actually doesn't work with fieldgroup enabled - needs some rework (and it will be pluggable as well)

Shadlington’s picture

A common use case will be something along the lines of a controlling checkbox that hides/reveals a set of child fields.
Is that within the scope or would it be better to use a dedicated module like conditional fields?

swentel’s picture

Hmm, maybe I do need to check out that module to see if I'm not doing any double work. So this might become a won't fix in the end.

Shadlington’s picture

I've only ever used it previously in a D6 site (without DS) and have no idea how well it plays with DS.
If it works with DS then that'd be great. Ensuring it does could probably be all that is required.

I'm not sure if it does that kind of switch case behaviour that your described in #3 though.

swentel’s picture

I've been trying the dev version but I can't get it to behave like I want on display level - even with no layout configured. Another problem is that DS fields are not recognized either and there is no hook. Still thinking about a simple implementation for DS (which could be hookable/pluggable)

yareckon’s picture

sub

Shadlington’s picture

FYI, a recent commit to conditional fields added: "Enhance effects system and add two new States: Filled with value / Emptied."

Which sounds like the type of condition you're after.

swentel’s picture

I've tried it out, but it doesn't work at all for me. We have another use case, coming from #1250144: Show block on specific pages settings not working, so I'll probably go ahead with an implementation of both in DS which can be pluggable as well.

swentel’s picture

Status: Needs work » Closed (duplicate)
muschpusch’s picture

I know the issue is closed as an duplicate but a temporary solution for solving this is writing a custom field formatter (which is a solution for 99% of my problems, thanks for the tip swentel).

This is a crapy code feel free to make it better ;) The magic happens in kg_formatter_field_formatter_view()

function kg_formatter_field_formatter_info() {
  return array(
    // the key must be unique, so it's best to prefix with your module's name.
    'kg_formatter' => array(
      // the label is is what is displayed in the select box in the UI.
      'label' => t('kg formatter'),   
      // field types is the important bit!! List the field types your formatter is for.
      'field types' => array('text'), 
    ),
  );
}

/**
 * Implements hook_field_formatter_settings_summary().
 */
function kg_formatter_field_formatter_settings_summary($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $summary = t('simple kg formatter'); // we use t() for translation and placeholders to guard against attacks
  return $summary;
}

/**
 * Implements hook_field_formatter_view().
 */
function kg_formatter_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {

 // here happens the magic: return the element when specs has a value! The whole entity object is available.
  if (!empty($items[0]['value']) && $entity->field_specs['und'][0]['value'] != 0 ){
    $kg = $items[0]['value']." kg"; 
    $element[0]['#markup']=$kg;     
    return $element;
  }
}