You are here

function openlayers_ui_get_behavior_options in Openlayers 6.2

Same name and namespace in other branches
  1. 7.2 modules/openlayers_ui/includes/openlayers_ui.maps.inc \openlayers_ui_get_behavior_options()

Get behavior options.

1 call to openlayers_ui_get_behavior_options()
openlayers_ui_presets_form in modules/openlayers_ui/includes/openlayers_ui.presets.inc
Menu Callback for Add Preset

File

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

Code

function openlayers_ui_get_behavior_options($type, $defaults) {
  $form = array();
  foreach (openlayers_behaviors() as $key => $plugin) {

    // Get behavior class
    $class = ctools_plugin_get_class($plugin, 'behavior');
    if (!empty($class)) {
      $options = isset($defaults['behaviors'][$key]) ? $defaults['behaviors'][$key] : array();
      $behavior = new $class($options, $defaults);
      if (!isset($plugin['ui_visibility']) || $plugin['ui_visibility']) {

        // Create basic form structure for behavior
        $form[$key] = array(
          'enabled' => array(
            '#type' => 'checkbox',
            '#title' => $plugin['title'],
            '#description' => $plugin['description'],
            '#default_value' => isset($defaults['behaviors'][$key]),
            '#id' => $key . '-enabled',
          ),
          'dependencies' => openlayers_dependency_widget($behavior
            ->js_dependency()),
          'options' => array(),
        );

        // Create options items
        $options = $behavior
          ->options_form($options);
        if (!empty($options)) {

          // HACK.  In order to use ctools form dependencies, we have to use a hidden
          // field as it supports processing and IDs.
          $form[$key]['options_set'][$key . '-prefix'] = array(
            '#type' => 'hidden',
            '#id' => $key . '-options',
            '#prefix' => '<div><fieldset id="' . $key . '-options' . '" class="collapsible">',
            '#process' => array(
              'ctools_dependent_process',
            ),
            '#dependency' => array(
              $key . '-enabled' => array(
                1,
              ),
            ),
            '#weight' => -1000,
          );
          $form[$key]['options_set']['options'] = $options;
          $form[$key]['options_set'][$key . '-suffix'] = array(
            '#value' => '</fieldset></div>',
            '#weight' => 1000,
          );
        }
      }
    }
  }
  return $form;
}