You are here

function masonry_fields_formatter_supported in Masonry Fields 7.3

Same name and namespace in other branches
  1. 8 masonry_fields.module \masonry_fields_formatter_supported()
  2. 7 masonry_fields.module \masonry_fields_formatter_supported()

Check if a given field formatter is supported.

Parameters

$context: The $context array provided by the Field Formatter Settings module. See field_formatter_settings.api.php for more information.

Return value

A boolean indicating the supported status.

2 calls to masonry_fields_formatter_supported()
masonry_fields_field_formatter_settings_form_alter in ./masonry_fields.module
Implements hook_field_formatter_settings_form_alter().
masonry_fields_field_formatter_settings_summary_alter in ./masonry_fields.module
Implements hook_field_formatter_settings_summary_alter().

File

./masonry_fields.module, line 94
Provides a field formatter for displaying multi-value fields in a Masonry layout.

Code

function masonry_fields_formatter_supported($context) {
  $formatter = $context['instance']['display'][$context['view_mode']];

  // Fields in Views aren't supported
  if (!isset($context['instance']['entity_type']) || $context['instance']['entity_type'] == 'ctools' && $context['instance']['bundle'] == 'ctools') {
    return FALSE;
  }

  // Get supported field types
  $field_types = masonry_fields_field_types();

  // Return TRUE for supported formatters with multi-value fields
  $field_type_supported = array_key_exists($context['field']['type'], $field_types);
  $formatter_supported = $field_type_supported && in_array($formatter['type'], $field_types[$context['field']['type']]);
  $multi_value_field = $context['field']['cardinality'] > 1 || $context['field']['cardinality'] == FIELD_CARDINALITY_UNLIMITED;
  if ($formatter_supported && $multi_value_field) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}