You are here

function styleswitcher_style_form in Style Switcher 7.2

Same name and namespace in other branches
  1. 6.2 styleswitcher.admin.inc \styleswitcher_style_form()

Page callback: Constructs a form to add/edit a style.

Parameters

array|null $style: (optional) Style to edit. The structure of an array is the same as returned from styleswitcher_style_load().

See also

styleswitcher_style_form_validate()

styleswitcher_style_form_submit()

styleswitcher_menu()

styleswitcher_style_load()

1 string reference to 'styleswitcher_style_form'
styleswitcher_menu in ./styleswitcher.module
Implements hook_menu().

File

./styleswitcher.admin.inc, line 199
Styleswitcher configuration functionality.

Code

function styleswitcher_style_form($form, &$form_state, $style = NULL) {
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#description' => t('Human-readable name for this style.'),
    '#default_value' => $style ? $style['label'] : '',
    '#required' => TRUE,
  );
  if ($style) {
    list(, $name_value) = explode('/', $style['name']);
  }
  $form['name'] = array(
    '#type' => 'machine_name',
    '#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'),
    '#default_value' => $style ? $name_value : '',
    '#field_prefix' => 'custom/',
    '#machine_name' => array(
      'source' => array(
        'label',
      ),
      'exists' => '_styleswitcher_style_exists',
    ),
  );
  if ($style) {

    // Show the warning about renaming styles.
    $form['name']['#description'] .= '<br />' . t('<strong>WARNING:</strong> if you change style machine name, users who have chosen this style will see the default one instead until they switch again.');
  }
  $form['old_name'] = array(
    '#type' => 'value',
    '#value' => $style ? $style['name'] : '',
  );
  $form['path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path'),
    '#description' => t('The path to the stylesheet file relative to the site root or an external CSS file.'),
    '#default_value' => $style ? $style['path'] : '',
    '#required' => TRUE,
    '#access' => !$style || isset($style['path']),
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['actions']['delete'] = array(
    '#type' => 'submit',
    '#value' => t('Delete'),
    // Do not allow to delete the blank style.
    '#access' => isset($style['path']),
  );
  return $form;
}