You are here

function openlayers_ui_get_behavior_options in Openlayers 7.2

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

Get behavior options.

1 call to openlayers_ui_get_behavior_options()
openlayers_maps_ui::edit_form in modules/openlayers_ui/plugins/export_ui/openlayers_maps_ui.class.php
Provide the actual editing form.

File

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

Code

function openlayers_ui_get_behavior_options($type, $defaults) {
  $form = array();
  $behaviors = openlayers_behaviors();
  $enabled_behaviors = array();
  foreach ($defaults['behaviors'] as $key => $options) {
    $enabled_behaviors[$key] = $behaviors[$key];
    unset($behaviors[$key]);
  }

  // Ordering behaviors
  // First display the enabled, then the disabled.
  uasort($enabled_behaviors, '_openlayers_ui_sort_behaviors');
  uasort($behaviors, '_openlayers_ui_sort_behaviors');
  $behaviors = array_merge($enabled_behaviors, $behaviors);
  foreach ($behaviors as $key => $plugin) {

    // Get behavior class
    $class = ctools_plugin_load_class('openlayers', 'behaviors', $key, '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(
          '#type' => 'fieldset',
          '#title' => $plugin['title'],
          '#collapsible' => TRUE,
          '#collapsed' => isset($defaults['behaviors'][$key]) ? FALSE : TRUE,
          'enabled' => array(
            '#type' => 'checkbox',
            '#title' => $plugin['title'],
            '#description' => $plugin['description'],
            '#default_value' => isset($defaults['behaviors'][$key]),
          ),
        );

        // Create options items
        $options = $behavior
          ->options_form($options);
        if (!empty($options)) {
          $form[$key]['options_set'] = array(
            '#type' => 'fieldset',
            '#title' => t('Options'),
            '#collapsible' => FALSE,
            '#collapsed' => FALSE,
            '#states' => array(
              'visible' => array(
                ':input[name="behaviors[' . $key . '][enabled]"]' => array(
                  'checked' => TRUE,
                ),
              ),
            ),
            'options' => $options,
          );
        }
      }
    }
  }
  return $form;
}