You are here

function ffc_field_attach_view_alter in Field formatter conditions 7

Implements hook_field_attach_view_alter().

File

./ffc.module, line 93
Field formatter conditions.

Code

function ffc_field_attach_view_alter(&$build, $context) {
  foreach (element_children($build) as $field_name) {
    $settings = array();

    // Check conditions, continue when nothing is configured.
    if ($build[$field_name]['#field_type'] == 'ds') {
      $field_settings = ds_get_field_settings($build[$field_name]['#entity_type'], $build[$field_name]['#bundle'], $context['view_mode']);
      $settings['conditions'] = array();
      if (!empty($field_settings[$field_name]['formatter_settings']['conditions'])) {
        $settings['conditions'] = $field_settings[$field_name]['formatter_settings']['conditions'];
      }
    }
    else {
      $settings = field_formatter_settings_get_instance_display_settings($build[$field_name]['#entity_type'], $field_name, $build[$field_name]['#bundle'], $context['view_mode']);
    }
    if (empty($settings['conditions'])) {
      continue;
    }

    // Execute conditions.
    foreach ($settings['conditions'] as $condition) {
      $callback = 'ffc_condition_execute_' . $condition['condition'];

      // Use function_exists because we don't clean up when modules are
      // disabled. It might be a good idea to do that in the future.
      if (function_exists($callback)) {
        $callback($build, $field_name, !empty($condition['configuration']) ? $condition['configuration'] : '', $context);
      }
    }
  }
}