You are here

function styles_ui_style_edit_form in Styles 7.2

Callback for the style edit form.

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

File

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

Code

function styles_ui_style_edit_form($form, $form_state, $field_type, $style_name) {
  $style = styles_style_load($field_type, $style_name);
  $form['field_type'] = array(
    '#type' => 'value',
    '#value' => $field_type,
  );
  $form['old_style_name'] = array(
    '#type' => 'value',
    '#value' => $style['name'],
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#description' => t('The name of this style, which must be a unique name containing only alphanumeric characters and underscores.'),
    '#default_value' => $style['name'],
    '#required' => TRUE,
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#description' => t('The description of the style.'),
    '#default_value' => $style['description'],
  );
  $form['containers'] = array(
    '#type' => 'vertical_tabs',
    '#tree' => TRUE,
  );
  $containers = styles_default_containers($field_type);
  $presets = styles_default_presets($field_type);
  foreach ($containers['containers'] as $container_name => $container) {
    $style = $presets['containers'][$container_name]['styles'][$style_name];
    $container_label = isset($container['label']) ? $container['label'] : $container_name;
    $form['containers'][$container_name] = array(
      '#type' => 'fieldset',
      '#title' => t('@container', array(
        '@container' => $container_label,
      )),
    );
    $options = array();
    foreach ($presets['containers'][$container_name]['presets'] as $preset_name => $preset) {
      $options[$preset_name] = t('@preset', array(
        '@preset' => $preset_name,
      ));
    }
    $default_value = isset($presets['containers'][$container_name]['styles'][$style_name]['preset']) ? $presets['containers'][$container_name]['styles'][$style_name]['preset'] : (isset($presets['containers'][$container_name]['styles'][$style_name]['default preset']) ? $presets['containers'][$container_name]['styles'][$style_name]['default preset'] : $presets['containers'][$container_name]['default preset']);
    $form['containers'][$container_name]['preset'] = array(
      '#type' => 'select',
      '#title' => t('Preset'),
      '#options' => $options,
      '#default_value' => $default_value,
    );
    $form['containers'][$container_name]['default_preset'] = array(
      '#type' => 'item',
      '#title' => t('Default preset'),
      '#markup' => t('%preset', array(
        '%preset' => $style['default preset'],
      )),
    );
    if (isset($container['preview'])) {
      $form['containers'][$container_name]['preview'] = array(
        '#type' => 'item',
        '#title' => t('Preview'),
        '#markup' => theme($container['preview'], array(
          'style_name' => $style_name,
        )),
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;

  //   $field_info = field_info_field_types($field_type);
  //   $presets = styles_default_presets();
  //   $preset = $presets[$field_type]['containers'][$preset_name];
  //   $styles_containers = styles_default_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',
  //   );
  //   $styles = styles_default_styles($field_type);
  //   dpm($styles);
  //
  //   // Begin the settings array to send to jQuery.
  //   $settings = array(
  //     'stylesUI' => array(
  //       'url' => url('styles-ui/preview'),
  //       'fieldType' => check_plain($field_type),
  //     ),
  //   );
  //   foreach ($styles['styles'] as $style_name => $style) {
  //     $form['containers'][$style_name] = array(
  //       '#type' => 'fieldset',
  //       '#title' => $style['label'],
  //     );
  //     if (isset($preset['styles'][$style_name]['current preset'])) {
  //       $this_preset = $preset['styles'][$style_name]['current preset'];
  //     }
  //     else {
  //       $this_preset = $preset['styles'][$style_name]['default preset'];
  //     }
  //     $options = array();
  //     foreach ($preset['presets'] as $preset_style_name => $effects) {
  //       $options[$preset_style_name] = $preset_style_name;
  //     }
  //
  //     // Store the container in the 'rel' attribute for later AJAX previews.
  //     $rel = check_plain($style_name);
  //     $form['containers'][$style_name]['preset_' . $style_name] = array(
  //       '#type' => 'radios',
  //       '#title' => t('Style effects preset'),
  //       '#default_value' => $this_preset,
  //       '#options' => $options,
  //       '#attributes' => array('class' => array('styles-ui-preset'), 'rel' => $rel),
  //     );
  //     // Add a preview.
  //     if (isset($styles_containers[$field_type]['themes']) && isset($styles_containers[$field_type]['themes']['preview'])) {
  //       $preview = '<div id="styles-ui-preview-wrapper-' . $rel . '" class="styles-ui-preview-wrapper">' . theme($styles_containers[$field_type]['themes']['preview'], array('field_type' => $field_type, 'container_name' => $style_name, 'style_name' => $this_preset)) . '</div>';
  //       $form['containers'][$style_name]['preview_' . $style_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;
}