function styleguide_palette_form in Style Guide 7
Form constructor for the style guide swatch form.
Parameters
string|null $theme: (optional) The theme to display palettes for. Defaults to NULL, which will fallback to the default theme.
See also
styleguide_palette_form_validate()
styleguide_palette_form_submit()
1 string reference to 'styleguide_palette_form'
- styleguide_palette_menu in styleguide_palette/
styleguide_palette.module - Implements hook_menu().
File
- styleguide_palette/
styleguide_palette.admin.inc, line 33 - Administrative page callbacks for the Style Guide Swatch module.
Code
function styleguide_palette_form($form, &$form_state, $theme = NULL) {
$form['colorpicker'] = array(
'#type' => 'container',
'#attributes' => array(
'id' => 'styleguide-palette-colorpicker',
'class' => array(
'element-hidden',
),
),
'#attached' => array(
'library' => array(
array(
'system',
'farbtastic',
),
),
'js' => array(
drupal_get_path('module', 'styleguide_palette') . '/js/styleguide_palette.js',
),
),
);
$theme = $theme ? $theme : variable_get('theme_default', 'bartik');
$swatches = array();
$results = styleguide_palette_swatch_load_multiple($theme);
foreach ($results as $swatch) {
$name = check_plain($swatch->name);
$swatches[$name]['theme'] = array(
'#type' => 'value',
'#value' => $theme,
);
$swatches[$name]['id'] = array(
'#type' => 'value',
'#value' => $swatch->id,
);
$swatches[$name]['description'] = array(
'#type' => 'value',
'#value' => $swatch->description,
);
$swatches[$name]['hex'] = array(
'#type' => 'textfield',
'#title' => $name,
'#default_value' => check_plain($swatch->hex),
'#description' => check_plain($swatch->description),
'#element_validate' => array(
'styleguide_palette_swatch_validate_hex',
),
'#size' => 7,
'#attributes' => array(
'class' => array(
'colorpicker-input',
),
),
);
$swatches[$name]['delete'] = array(
'#type' => 'link',
'#title' => t('Delete'),
'#href' => "admin/config/user-interface/styleguide-palette/delete/{$swatch->id}",
);
}
if (!empty($swatches)) {
$form['palette'] = array(
'#type' => 'fieldset',
'#title' => t('Color palette'),
'#tree' => TRUE,
);
$form['palette'] += $swatches;
}
$form['add_swatch'] = array(
'#type' => 'fieldset',
'#title' => t('Add a swatch'),
);
$form['add_swatch']['theme'] = array(
'#type' => 'value',
'#value' => $theme,
);
$form['add_swatch']['name'] = array(
'#type' => 'textfield',
'#title' => t('Swatch name'),
);
$form['add_swatch']['description'] = array(
'#type' => 'textfield',
'#title' => t('Swatch description'),
);
$form['add_swatch']['hex'] = array(
'#type' => 'textfield',
'#title' => t('Hex value'),
'#element_validate' => array(
'styleguide_palette_swatch_validate_hex',
),
'#attributes' => array(
'class' => array(
'colorpicker-input',
),
),
'#size' => 7,
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save palette'),
);
return $form;
}