You are here

function openlayers_cck_widget_settings in Openlayers 6.2

Same name and namespace in other branches
  1. 6 modules/openlayers_cck/openlayers_cck.module \openlayers_cck_widget_settings()

Implementation of hook_widget_settings().

File

modules/openlayers_cck/openlayers_cck.module, line 238
This file holds the main Drupal hook functions and private functions for the openlayers_cck module.

Code

function openlayers_cck_widget_settings($op, $widget) {
  switch ($op) {
    case 'form':

      // Get Presets
      $presets = openlayers_preset_options();
      $default_preset = variable_get('openlayers_default_preset', 'default');

      // Define form elements
      $form['openlayers_cck_preset_map'] = array(
        '#type' => 'select',
        '#title' => t('Input Map Preset'),
        '#description' => t('Choose the OpenLayers Preset Map that will ' . 'be used to input the data.'),
        '#options' => $presets,
        '#default_value' => isset($widget['openlayers_cck_preset_map']) ? $widget['openlayers_cck_preset_map'] : $default_preset,
      );
      $form['openlayers_behaviors'] = array(
        '#type' => 'fieldset',
        '#title' => t('Formatter Behaviors'),
        '#description' => t('These behaviors are specifically for the
          CCK formatter layer.'),
        '#collapsible' => TRUE,
        '#tree' => TRUE,
      );

      // Add behavior options.  Ideally this could pull
      // dynamically from behavior definitions, but is
      // manually pulling now.
      $map = array(
        'layers' => array(
          'openlayers_cck_vector_layer' => 'openlayers_cck_vector_layer',
        ),
      );
      foreach (openlayers_behaviors() as $key => $plugin) {

        // Get behavior class
        $class = ctools_plugin_get_class($plugin, 'behavior');

        // Specific call
        if ($key == 'openlayers_behavior_zoomtolayer') {

          // Build form.
          $form['openlayers_behaviors'][$key] = array(
            '#tree' => TRUE,
            '#type' => 'fieldset',
            '#title' => $plugin['title'],
            '#description' => $plugin['description'],
            'enabled' => array(
              '#type' => 'checkbox',
              '#title' => t('Enabled'),
              '#default_value' => isset($widget['openlayers_behaviors'][$key]['enabled']) ? $widget['openlayers_behaviors'][$key]['enabled'] : FALSE,
            ),
          );

          // Get options and add form elements
          $options = isset($widget['openlayers_behaviors'][$key]) ? $widget['openlayers_behaviors'][$key] : array();
          $behavior = new $class($options, $map);
          $form['openlayers_behaviors'][$key]['options'] = $behavior
            ->options_form($options['options']);
        }
      }

      // Return form
      return $form;
    case 'save':
      return array(
        'openlayers_cck_preset_map',
        'openlayers_behaviors',
      );
  }
}