You are here

function styles_ui_preset_edit_form in Styles 7

Same name and namespace in other branches
  1. 6.2 contrib/styles_ui/includes/styles_ui.admin.inc \styles_ui_preset_edit_form()
  2. 6 contrib/styles_ui/includes/styles_ui.admin.inc \styles_ui_preset_edit_form()

Callback for the preset edit form.

1 string reference to 'styles_ui_preset_edit_form'
styles_ui_menu in contrib/styles_ui/styles_ui.module
Implements hook_menu().

File

contrib/styles_ui/styles_ui.admin.inc, line 100
Administrative page callbacks for the Styles UI module.

Code

function styles_ui_preset_edit_form($form, $form_state, $field_type, $preset_name) {
  $field_info = field_info_field_types($field_type);
  $presets = styles_presets();
  $preset = $presets[$field_type][$preset_name];
  $styles_containers = styles_containers();
  $containers = $styles_containers[$field_type]['containers'];
  drupal_set_title(t('Edit @field_type style preset: @preset', array(
    '@field_type' => $field_info['label'],
    '@preset' => $preset_name,
  )));
  $form = array();
  $form['containers'] = array(
    '#type' => 'vertical_tabs',
  );

  // Begin the settings array to send to jQuery.
  $settings = array(
    'stylesUI' => array(
      'url' => url('styles-ui/preview'),
      'fieldType' => check_plain($field_type),
    ),
  );
  foreach ($containers as $container_name => $container) {
    $form['containers'][$container_name] = array(
      '#type' => 'fieldset',
      '#title' => $container['label'],
    );
    $this_preset = array_pop($preset[$container_name]);
    $options = array();
    foreach ($container['available styles'] as $style_name => $style) {
      $options[$style_name] = $style_name;
    }

    // Store the container in the 'rel' attribute for later AJAX previews.
    $rel = check_plain($container_name);
    $form['containers'][$container_name]['preset_' . $container_name] = array(
      '#type' => 'radios',
      '#title' => t('Style preset'),
      '#default_value' => $this_preset['name'],
      '#options' => $options,
      '#attributes' => array(
        'class' => array(
          'styles-ui-preset',
        ),
        'rel' => $rel,
      ),
    );

    // Add a preview.
    if (isset($containers[$container_name]['themes']['preview'])) {
      $preview = '<div id="styles-ui-preview-wrapper-' . $rel . '" class="styles-ui-preview-wrapper">' . theme($containers[$container_name]['themes']['preview'], array(
        'field_type' => $field_type,
        'container_name' => $container_name,
        'preset_name' => $this_preset['name'],
      )) . '</div>';
      $form['containers'][$container_name]['preview_' . $container_name] = array(
        '#type' => 'item',
        '#title' => t('Style preview'),
        '#markup' => $preview,
      );
    }
  }

  // Add the javascript for live previews on radio select.
  $form['#attached'] = array(
    'js' => array(
      drupal_get_path('module', 'styles_ui') . '/styles_ui.js',
    ),
  );
  drupal_add_js($settings, array(
    'type' => 'setting',
  ));
  return $form;
}