You are here

function openlayers_ui_styles_form in Openlayers 6.2

Styles add/edit form.

1 string reference to 'openlayers_ui_styles_form'
openlayers_ui_menu in modules/openlayers_ui/openlayers_ui.module
Implementation of hook_menu

File

modules/openlayers_ui/includes/openlayers_ui.styles.inc, line 254
This file holds the functions handling styles in the Openlayers UI.

Code

function openlayers_ui_styles_form(&$form_state, $style = NULL, $edit = FALSE) {
  $form = array();
  $properties = openlayers_ui_styles_get_properties();
  $style_data = !empty($style->data) ? $style->data : array();

  // Pass style data along
  $form['style_data'] = array(
    '#type' => 'value',
    '#value' => array(
      'definitions' => $properties,
      'defaults' => $style_data,
    ),
  );

  // Style object basics
  $form['info'] = array(
    '#type' => 'fieldset',
    '#tree' => FALSE,
    '#title' => t('Basic Information'),
    '#description' => t('The basic information for the style, used to refer to and describe the style.'),
    '#collapsible' => TRUE,
  );
  $form['info']['name'] = array(
    '#title' => t('Name'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#default_value' => !empty($style->name) ? $style->name : '',
  );
  $form['info']['title'] = array(
    '#title' => t('Title'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#default_value' => !empty($style->title) ? $style->title : '',
  );
  $form['info']['description'] = array(
    '#title' => t('Description'),
    '#type' => 'textfield',
    '#default_value' => !empty($style->description) ? $style->description : '',
  );

  // OpenLayers style properties
  $form['data'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#title' => t('Style Properties and Plugins'),
    '#description' => t('Style properties are properties as
      defined by the OpenLayers library.  Plugins are dynamically
      process the layer at render time; plugins may override the
      values that you have set for style properies.'),
    '#collapsible' => TRUE,
  );
  foreach ($properties as $key => $prop) {
    $form['data'][$key] = array(
      '#type' => 'fieldset',
      '#tree' => TRUE,
      '#title' => $key,
      '#description' => $prop['desc'],
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $def_value = $prop['default'];
    $def_use_plugin = '';
    if (isset($style_data[$key])) {
      if (is_array($style_data[$key])) {
        $def_use_plugin = $style_data[$key]['plugin'];
      }
      else {
        $def_value = $style_data[$key];
      }
    }

    // Add plugin options, if any
    $handling_plugins = openlayers_ui_get_style_plugins_for_property($key);
    if (!empty($handling_plugins)) {
      $plugin_options = array(
        '' => t('none'),
      );
      foreach ($handling_plugins as $plugname => $plug) {
        $plugin_options[$plugname] = $plug['title'];
      }
      $form['data'][$key]['uses_plugin'] = array(
        '#title' => t('Use plugin'),
        '#type' => 'select',
        '#options' => $plugin_options,
        '#default_value' => $def_use_plugin,
        '#ahah' => array(
          'path' => 'openlayers/ahah/style_plugin/' . $key,
          'wrapper' => $key . '-style-plugin',
          'method' => 'replace',
          'effect' => 'fade',
        ),
      );
    }

    // Hackish... but is that new for HTML ? ...
    $form['data'][$key]['plugin_conf_start'] = array(
      '#value' => '<div id="' . $key . '-style-plugin">',
    );
    if (isset($style_data[$key]) && is_array($style_data[$key])) {
      $defaults = $style_data[$key]['conf'];
      $plugname = $style_data[$key]['plugin'];
      $form['data'][$key]['plugin'] = openlayers_ui_get_style_plugin_form($def_use_plugin, $defaults);
    }
    else {
      $form['data'][$key]['value'] = array(
        '#type' => !isset($prop['options']) ? 'textfield' : 'select',
        '#default_value' => $def_value,
      );

      // Add options if needed
      if (isset($prop['options']) && is_array($prop['options'])) {
        $form['data'][$key]['value']['#options'] = $prop['options'];
      }
    }

    // Hackish... but is that new for HTML ? ...
    $form['data'][$key]['plugin_conf_end'] = array(
      '#value' => '</div>',
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}