_openlayers_behaviors_process

openlayers/openlayers.module, line 548

Versions
6
_openlayers_behaviors_process($behaviors = array(), &$map)

Process Behaviors

Get full data for any behaviors and add handlers

Parameters

$layers Array of layers to process

$map Map array

Return value

Array of processed behaviors

Code

<?php
function _openlayers_behaviors_process($behaviors = array(), &$map) {
  // Check input
  if (!is_array($behaviors)) {
    $behaviors = array();
  }
  if (!is_array($map)) {
    $map = array();
  }
  
  // Initialized variables
  $processed = array();
  // Get behavior info array
  $behavior_info = openlayers_behaviors_get_info();
  
  // Go through behaviors
  foreach ($behaviors as $k => $behavior) {
    // Check if array, if array, just pass on
    if (is_array($behaviors)) {
      $processed[$behavior['id']] = $behavior;
    }
    else {
      $processed[$behavior] = array(
        'id' => $behavior,
        'type' => $behavior,
      );
    }
  }
  
  // Go through processed
  foreach ($processed as $bkey => $behavior) {
    $info = $behavior_info[$behavior['type']];
    
    if (is_file($info['file'])) {
      require_once $info['file'];
      // Check for function
      if (function_exists($info['callback'])) {
        // Call function and give it the behavior array
        $result = call_user_func_array($info['callback'], array($behavior, &$map));
        // Check for result
        if (isset($result) && is_array($result)) {
          $result['js_callback'] = $info['js_callback'];
          $processed[$bkey] = $result;
        }
      }
      // Include JavaScript
      if ($info['js_file']){
        drupal_add_js($info['js_file'], 'module');
      }
    }
  }
    
  // Return processed
  return $processed;
}
?>