You are here

function ffc_get_condition_fields in Field formatter conditions 7

API function: get all fields for the current context.

Parameters

$context: A collection of keys:

  • entity_type: The name of the entity type
  • bundle: The name of the bundle
  • view_mode: The name of the view mode
  • field_name: The name of the field
  • ds_layout: Whether a Display Suite layout is configured or not.

If you implement a condition form, simply pass on the $context variable that is passed to that callback to this function, otherwise you will have to construct it yourself.

$exclude_current_field: Whether to exclude the current field or not.

Return value

A collection of fields on the current entity type and bundle

4 calls to ffc_get_condition_fields()
ffc_condition_form_hide_if_empty in ./ffc.ffc_conditions_info.inc
Field formatter conditional form.
ffc_condition_form_hide_if_string in ./ffc.ffc_conditions_info.inc
Field formatter conditional form.
ffc_condition_form_hide_not_empty in ./ffc.ffc_conditions_info.inc
Field formatter conditional form.
ffc_condition_form_hide_no_string in ./ffc.ffc_conditions_info.inc
Field formatter conditional form.

File

./ffc.ffc_conditions_info.inc, line 145
Hook implementations and API functions for Field formatter settings.

Code

function ffc_get_condition_fields($context, $exclude_current_field = TRUE) {

  // Get the context.
  $entity_type = $context['entity_type'];
  $bundle = $context['bundle'];
  $view_mode = $context['view_mode'];
  $current_field = $context['field_name'];
  $condition_fields = array();

  // Get Field API fields.
  $instances = field_info_instances($entity_type, $bundle);
  foreach ($instances as $field_name => $instance) {
    if ($field_name == $current_field && $exclude_current_field) {
      continue;
    }
    $condition_fields[$field_name] = $instance['label'];
  }

  // Get Display Suite fields.
  if (module_exists('ds') && !empty($context['ds_layout'])) {
    $ds_fields = ds_get_fields($entity_type);
    foreach ($ds_fields as $key => $field) {
      if ($key == $current_field && $exclude_current_field) {
        continue;
      }

      // Check on ui_limit.
      if (isset($field['ui_limit'])) {
        $continue = TRUE;
        foreach ($field['ui_limit'] as $limitation) {
          list($limit_bundle, $limit_view_mode) = explode('|', $limitation);
          if ($limit_bundle == '*' || $limit_bundle == $bundle) {
            if ($limit_view_mode == '*' || $limit_view_mode == $view_mode) {
              $continue = FALSE;
            }
          }
        }
        if ($continue) {
          continue;
        }
      }
      $condition_fields[$key] = $field['title'];
    }
  }
  return $condition_fields;
}