function ds_extras_form_node_form_alter in Display Suite 7.2
Same name and namespace in other branches
- 7 modules/ds_extras/ds_extras.module \ds_extras_form_node_form_alter()
Implements hook_form_FORM_ID_alter().
File
- modules/
ds_extras/ ds_extras.module, line 377 - Display Suite extras main functions.
Code
function ds_extras_form_node_form_alter(&$form, $form_state, $form_id) {
$node = $form['#node'];
// Switch full view mode.
if (user_access('ds_switch ' . $node->type)) {
// Get the view modes.
$view_modes = ds_extras_get_bundle_view_modes('node', $node->type);
$enabled_vm = variable_get('ds_extras_view_modes_' . $node->type, array_keys($view_modes));
$layouts = array();
$options = array();
foreach ($view_modes as $key => $label) {
if (in_array($key, $enabled_vm)) {
$layout = ds_get_layout('node', $node->type, $key, FALSE);
$layouts[$key] = $layout;
$options[$key] = $label;
}
}
// Only fire if we have more than 1 option.
if (count($options) > 1) {
if (!isset($form['ds_extras'])) {
$form['ds_extras'] = array(
'#type' => 'fieldset',
'#title' => t('Display settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#weight' => 100,
);
}
$form['ds_extras']['ds_switch'] = array(
'#type' => 'select',
'#title' => t('View mode'),
'#options' => $options,
'#default_value' => isset($node->ds_switch) ? $node->ds_switch : 'default',
'#description' => t('Switch to a different view mode to display the full page view of this node.'),
'#weight' => -1,
'#ajax' => array(
'callback' => 'ds_extras_switch_view_mode_preview_callback',
'wrapper' => 'ds_switch_preview_wrapper',
),
);
$form['ds_extras']['preview'] = array(
'#type' => 'container',
'#prefix' => '<div id="ds_switch_preview_wrapper">',
'#suffix' => '</div>',
);
$fallback_image = drupal_get_path('module', 'ds') . '/images/preview.png';
$mode = isset($form_state['input']['ds_switch']) ? $form_state['input']['ds_switch'] : (isset($node->ds_switch) ? $node->ds_switch : 'default');
if (isset($layouts[$mode])) {
$chosen_layout = $layouts[$mode];
$image = isset($chosen_layout['image']) && !empty($chosen_layout['image']) ? $chosen_layout['path'] . '/' . $chosen_layout['layout'] . '.png' : $fallback_image;
if (isset($chosen_layout['panels']) && !empty($chosen_layout['panels']['icon'])) {
$image = $chosen_layout['panels']['path'] . '/' . $chosen_layout['panels']['icon'];
}
}
else {
$image = $fallback_image;
}
$form['ds_extras']['preview']['image'] = array(
'#markup' => '<div class="ds-layout-preview-image"><img src="' . base_path() . $image . '"/></div>',
);
}
}
}