You are here

function responsive_preview_device_configuration_form in Responsive Theme Preview 7

Builds a form that represents a device definition.

Parameters

$device: (Optional) An associative array that represents the definition of a device.

Return value

An associative array representing the form definition.

2 calls to responsive_preview_device_configuration_form()
responsive_preview_device_add_form in ./responsive_preview.admin.inc
Form callback: builds the form for adding a device.
responsive_preview_device_edit_form in ./responsive_preview.admin.inc
Form builder for the device editing form.

File

./responsive_preview.admin.inc, line 442
Administrative page callbacks for the responsive_preview module.

Code

function responsive_preview_device_configuration_form($device = array()) {
  $form = array(
    'device' => array(
      '#tree' => TRUE,
    ),
  );
  $form['device']['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Device name'),
    '#default_value' => !empty($device['label']) ? $device['label'] : NULL,
    '#size' => 30,
    '#required' => TRUE,
    '#maxlength' => 64,
  );
  $form['device']['name'] = array(
    '#type' => 'machine_name',
    '#default_value' => !empty($device['name']) ? $device['name'] : NULL,
    '#required' => TRUE,
    '#size' => 30,
    '#maxlength' => 64,
    '#machine_name' => array(
      'exists' => 'responsive_preview_get_device_definition',
      'source' => array(
        'device',
        'label',
      ),
      'replace_pattern' => '[^0-9a-z_\\-]',
      'error' => t('Please only use lowercase alphanumeric characters, underscores (_), and hyphens (-) for style names.'),
    ),
  );
  $form['device']['dimensions'] = array(
    '#type' => 'container',
    '#tree' => TRUE,
  );
  $form['device']['dimensions']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => !empty($device['width']) ? $device['width'] : NULL,
    '#field_suffix' => 'px',
    '#size' => 6,
    '#required' => TRUE,
  );
  $form['device']['dimensions']['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Height'),
    '#default_value' => !empty($device['height']) ? $device['height'] : NULL,
    '#field_suffix' => 'px',
    '#size' => 6,
    '#required' => TRUE,
  );
  $form['device']['dimensions']['dppx'] = array(
    '#type' => 'textfield',
    '#title' => t('Dots per pixel (dppx)'),
    '#description' => t('Size of a single dot in graphical representation. Classic desktop displays have 1dppx, typical modern smartphones and laptops have 2dppx or higher. For example Google Nexus 4 and iPhone 5 has 2dppx, while Google Nexus 7 has 1.325dppx and Samsung Galaxy S4 has 3dppx.'),
    '#default_value' => !empty($device['dppx']) ? $device['dppx'] : NULL,
    '#size' => 4,
    '#required' => TRUE,
  );
  $form['device']['orientation'] = array(
    '#type' => 'select',
    '#title' => t('Default orientation'),
    '#default_value' => !empty($device['orientation']) ? $device['orientation'] : NULL,
    '#options' => array(
      'portrait' => t('Portrait'),
      'landscape' => t('Landscape'),
    ),
  );
  $form['device']['status'] = array(
    '#type' => 'value',
    '#value' => !empty($device['status']) ? $device['status'] : 1,
  );
  $form['device']['weight'] = array(
    '#type' => 'value',
    '#value' => !empty($device['weight']) ? $device['weight'] : 0,
  );
  return $form;
}