function semantic_fields_form_alter in Semantic Fields 7
Implements hook_form_alter().
File
- ./
semantic_fields.module, line 22 - The functionality of the module
Code
function semantic_fields_form_alter(&$form, &$form_state, $form_id) {
// Manage Display forms.
if ($form_id == "field_ui_display_overview_form") {
$entity_type = $form['#entity_type'];
$bundle = $form['#bundle'];
$view_mode = $form['#view_mode'];
$form['fields']['#header'][] = t('Field format');
foreach (element_children($form['fields']) as $name) {
$instance = field_info_instance($entity_type, $name, $bundle);
$display = $instance['display'][$view_mode];
$settings = isset($form_state['formatter_settings'][$name]) ? $form_state['formatter_settings'][$name] : $display['settings'];
$options = semantic_fields_get_preset_options();
$options = array(
'default' => t('Default'),
) + $options;
$default_format = isset($instance['settings']['semantic_field_format']) ? $instance['settings']['semantic_field_format'] : NULL;
if (!isset($options[$default_format])) {
$default_format = NULL;
}
$form['fields'][$name]['semantic_field_format'] = array(
'#type' => 'select',
'#options' => $options,
'#empty_option' => isset($default_format) ? t('Field default (!default_value)', array(
'!default_value' => $options[$default_format],
)) : t('Field default (Default)'),
'#default_value' => isset($settings['semantic_field_format']) ? $settings['semantic_field_format'] : '',
);
}
$form['#submit'] = array_merge(array(
'semantic_fields_field_ui_display_overview_form_submit',
), $form['#submit']);
}
elseif ($form_id == "field_ui_field_edit_form") {
$instance = $form['#instance'];
$entity_type = $instance['entity_type'];
$bundle = $instance['bundle'];
$settings = $instance['settings'];
$form['instance']['settings']['semantic_field_format'] = array(
'#title' => t('<em>Default</em> field format'),
'#description' => t('The default markup used when rendering this field. This may be overridden in the Manage Display UI.'),
'#type' => 'select',
'#options' => semantic_fields_get_preset_options(),
'#empty_option' => t('Default'),
'#default_value' => isset($settings['semantic_field_format']) ? $settings['semantic_field_format'] : '',
);
}
}