You are here

function farm_map_add_behavior in farmOS 7

Add a farmOS-map behavior to the page.

Parameters

string $behavior: The behavior name.

array $settings: Optionally provide settings to override defaults.

11 calls to farm_map_add_behavior()
farm_area_farm_map_view in modules/farm/farm_area/farm_area.farm_map.inc
Implements hook_farm_map_view().
farm_area_generate_farm_map_view in modules/farm/farm_area/farm_area_generate/farm_area_generate.farm_map.inc
Implements hook_farm_map_view().
farm_mapknitter_farm_map_view in modules/farm/farm_mapknitter/farm_mapknitter.farm_map.inc
Implements hook_farm_map_view().
farm_map_farm_map_view in modules/farm/farm_map/farm_map.farm_map.inc
Implements hook_farm_map_view().
farm_map_geofield_farm_map_view in modules/farm/farm_map/farm_map_geofield/farm_map_geofield.farm_map.inc
Implements hook_farm_map_view().

... See full list

File

modules/farm/farm_map/farm_map.module, line 236

Code

function farm_map_add_behavior($behavior, $settings = array()) {

  // Ask modules for behaviors.
  $hook = 'farm_map_behaviors';
  $modules = module_implements($hook);
  foreach ($modules as $module) {

    // Get the module's behaviors.
    $behaviors = module_invoke($module, $hook);

    // If the desired behavior isn't defined, skip.
    if (!(array_key_exists($behavior, $behaviors) && !empty($behaviors[$behavior]['js']))) {
      continue;
    }

    // If the module defines settings for the behavior, add them as JS settings.
    $settings_hook = 'farm_map_behavior_settings';
    $default_settings = array();
    if (function_exists($module . '_' . $settings_hook)) {
      $default_settings = module_invoke($module, $settings_hook, $behavior);
    }
    $settings = array_merge($default_settings, $settings);
    if (!empty($settings)) {
      drupal_add_js(array(
        'farm_map' => array(
          'behaviors' => array(
            $behavior => $settings,
          ),
        ),
      ), array(
        'type' => 'setting',
      ));
    }

    // Add the behavior JS to the page.
    $path = drupal_get_path('module', $module) . '/' . $behaviors[$behavior]['js'];
    drupal_add_js($path);
  }
}