0

How can I get the field settings in a field preprocess hook?

1 Answer 1

0

You can fetch the field settings in a preprocess hook by using the following code.

function YOUR_THEME_preprocess_field(&$variables) {
  if($variables['element']['#field_name'] == 'field_event_date') {
    $node = $variables['element']['#object'];
    $field_name = 'field_event_date';
    $instance = field_info_instance('node', $field_name, $node->type);
    $display = field_get_display($instance, 'default', $node);
    $variables['event_date_formate'] = $display['settings']['format_type'];
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.