You are here

openlayers_ui.module in Openlayers 7.3

Administrative UI for openlayers.

File

modules/openlayers_ui/openlayers_ui.module
View source
<?php

/**
 * @file
 * Administrative UI for openlayers.
 */

/**
 * Implements hook_menu().
 */
function openlayers_ui_menu() {
  $items = array();

  // Core Openlayers settings pages.
  $items['admin/structure/openlayers'] = array(
    'title' => 'Openlayers',
    'description' => 'Manage maps, layers, sources, controls, styles, and interactions.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'openlayers_ui_admin_settings',
    ),
    'access arguments' => array(
      'administer openlayers',
    ),
    'file' => 'includes/openlayers_ui.admin.inc',
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/structure/openlayers/settings'] = array(
    'title' => 'Settings',
    'access arguments' => array(
      'administer openlayers',
    ),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 15,
  );
  return $items;
}

/**
 * Implements hook_ctools_plugin_directory().
 */
function openlayers_ui_ctools_plugin_directory($owner, $plugin_type) {
  return 'src/Plugin/' . str_replace("\\", DIRECTORY_SEPARATOR, $plugin_type);
}

/**
 * Implements hook_ctools_plugin_api().
 */
function openlayers_ui_ctools_plugin_api($module, $api) {
  return array(
    'version' => 1,
    'path' => drupal_get_path('module', 'openlayers_ui') . '/includes',
  );
}

/**
 * Implements hook_help().
 */
function openlayers_ui_help($path, $arg) {
  $output = NULL;
  switch ($path) {
    case 'admin/help#openlayers':
      $output = t('Openlayers is a module who displays information on a map using the <a href="@url">Openlayers library</a>.', array(
        '@url' => 'http://openlayers.org/',
      ));
      break;
    case 'admin/structure/openlayers':
      $output = t('Openlayers configuration and settings.');
      break;
    case 'admin/structure/openlayers/maps':
      $output = t('Manage the Openlayers maps.');
      break;
    case 'admin/structure/openlayers/projections':
      $output = t('Managing projections is not yet ready. Feel free to contribute.');
      break;
    case 'admin/structure/openlayers/styles':
      $output = t('Manage the Openlayers styles for the features displayed on maps.');
      break;
    case 'admin/structure/openlayers/layers':
      $output = t('Manage the Openlayers layers. Maps are composed of layers.');
      break;
    case 'admin/structure/openlayers/sources':
      $output = t('Manage the Openlayers sources. Layers must have a source defined.');
      break;
    case 'admin/structure/openlayers/controls':
      $output = t('Manage the Openlayers controls. Maps are composed of controls.');
      break;
    case 'admin/structure/openlayers/interactions':
      $output = t('Manage the Openlayers interactions. Maps are composed of interactions.');
      break;
    case 'admin/structure/openlayers/components':
      $output = t('Manage the custom components. These components are JS objects that are triggered after the map has been created.');
      break;
  }
  if (isset($output)) {
    return '<p>' . $output . '</p>';
  }
}

/**
 * Implements hook_menu_local_tasks_alter().
 */
function openlayers_ui_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  $path = 'admin/structure/openlayers';
  if (substr($root_path, 0, 26) == $path) {
    $path_exploded = explode('/', $root_path);
    foreach (\Drupal\openlayers\Openlayers::getPluginTypes() as $plugin_type) {
      if (count($path_exploded) >= 4) {
        if ($path_exploded[3] == $plugin_type . 's') {
          continue;
        }
      }
      $data['actions']['output'][] = array(
        '#theme' => 'menu_local_action',
        '#link' => array(
          'path' => $path . '/' . $plugin_type . 's/add',
          'title' => t('Add new @plugin_type', array(
            '@plugin_type' => $plugin_type,
          )),
          'href' => $path . '/' . $plugin_type . 's/add',
        ),
      );
    }
  }
}