function er_viewmode_field_widget_form_alter in Entity reference viewmode selector 7
Implements hook_field_widget_form_alter().
File
- ./
er_viewmode.module, line 15
Code
function er_viewmode_field_widget_form_alter(&$element, &$form_state, $context) {
$field = $context['field'];
$instance = $context['instance'];
if (er_viewmode_supported_field_widget($field)) {
$item = isset($context['items'][$context['delta']]) ? $context['items'][$context['delta']] : NULL;
$target_type = $field['settings']['target_type'];
$view_modes = er_viewmode_get_view_modes($field, $instance);
$instance = $context['instance'];
if (in_array($instance['widget']['type'], array(
'entityreference_autocomplete',
'options_select',
'options_buttons',
))) {
$element['view_mode'] = array(
'#type' => 'select',
'#title' => 'View Mode',
'#title_display' => 'invisible',
'#options' => $view_modes,
'#default_value' => isset($item) ? $item['view_mode'] : 'full',
'#weight' => 10,
'#id' => 'view-mode-' . $context['delta'],
);
}
}
}