You are here

function ds_edit_view_mode_form in Display Suite 7

Same name and namespace in other branches
  1. 7.2 modules/ds_ui/includes/ds.view_modes.inc \ds_edit_view_mode_form()

Manage a custom view mode.

2 string references to 'ds_edit_view_mode_form'
ds_menu in ./ds.module
Implements hook_menu().
ds_test_rel_build_info in tests/ds_test.module
Implements hook_rel_build_info().

File

./ds.view_modes.inc, line 59
Administrative functions for managing view modes for every entity.

Code

function ds_edit_view_mode_form($form, &$form_state, $view_mode = '') {
  ctools_include('export');
  $view_modes = ctools_export_crud_load_all('ds_view_modes');
  if (isset($view_modes[$view_mode])) {
    $view_mode = $view_modes[$view_mode];
  }
  else {
    $view_mode = new stdClass();
    $view_mode->label = '';
    $view_mode->view_mode = '';
    $view_mode->entities = array();
  }
  $form['name'] = array(
    '#title' => t('Label'),
    '#type' => 'textfield',
    '#default_value' => $view_mode->label,
    '#description' => t('The human-readable label of the view mode. This name must be unique.'),
    '#required' => TRUE,
    '#maxlength' => 32,
    '#size' => 30,
  );
  $form['view_mode'] = array(
    '#title' => t('Machine name'),
    '#type' => 'machine_name',
    '#default_value' => $view_mode->view_mode,
    '#maxlength' => 32,
    '#description' => t('The machine-readable name of this view mode. This name must contain only lowercase letters and underscores. This name must be unique.'),
    '#disabled' => !empty($view_mode->view_mode),
    '#machine_name' => array(
      'exists' => 'ds_view_mode_unique',
    ),
  );
  $entity_options = array();
  $entities = entity_get_info();
  foreach ($entities as $entity_type => $entity_info) {
    if (isset($entity_info['fieldable']) && $entity_info['fieldable']) {
      $entity_options[$entity_type] = drupal_ucfirst(str_replace('_', ' ', $entity_type));
    }
  }
  $form['entities'] = array(
    '#title' => t('Entities'),
    '#description' => t('Select the entities for which this view mode will be made available.'),
    '#type' => 'checkboxes',
    '#required' => TRUE,
    '#options' => $entity_options,
    '#default_value' => $view_mode->entities,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['existing'] = array(
    '#type' => 'value',
    '#value' => !empty($view_mode->view_mode),
  );
  return $form;
}