You are here

function custom_formatters_ds_fields_info_alter in Custom Formatters 7.2

Implements hook_ds_fields_info_alter().

File

includes/ds.inc, line 68
Display Suite module integration.

Code

function custom_formatters_ds_fields_info_alter(&$fields, $entity_type) {
  $formatters = custom_formatters_crud_load_all();
  foreach ($formatters as $formatter) {
    foreach (drupal_explode_tags($formatter->field_types) as $field_type) {
      if (strpos($field_type, 'ds_') === 0) {
        $field_type = substr($field_type, 3);
        if (isset($fields[$field_type])) {
          switch ($fields[$field_type]['field_type']) {
            case DS_FIELD_TYPE_PREPROCESS:
              if (!isset($fields[$field_type]['properties']['formatters'])) {
                $fields[$field_type]['properties']['formatters'] = array(
                  'default' => t('Default'),
                );
              }
              $fields[$field_type]['properties']['formatters']['custom_formatters_' . $formatter->name] = $formatter->label;
              if (isset($formatter->fapi)) {
                ob_start();
                eval($formatter->fapi);
                ob_get_clean();
                if (isset($form)) {
                  foreach ($form as $form_key => $element) {
                    $fields[$field_type]['properties']['default'][$form_key] = isset($element['#default_value']) ? $element['#default_value'] : '';
                    $fields[$field_type]['properties']['settings'][$form_key] = array(
                      'type' => $element['#type'],
                      'description' => isset($element['#description']) ? $element['#description'] : '',
                      'options' => isset($element['#options']) ? $element['#options'] : array(),
                    );
                  }
                }
              }
              break;
            case DS_FIELD_TYPE_FUNCTION:
              if (!isset($fields[$field_type]['#custom_formatters'])) {
                $fields[$field_type]['#original_field'] = $fields[$field_type];
                $fields[$field_type]['#custom_formatters'] = TRUE;
                $fields[$field_type]['function'] = 'custom_formatters_ds_render_field';
              }
              $fields[$field_type]['properties']['formatters']['custom_formatters_' . $formatter->name] = $formatter->label;
              break;
          }
        }
      }
    }
  }
}