You are here

function openlayers_ui_admin_settings in Openlayers 7.3

Same name and namespace in other branches
  1. 6.2 modules/openlayers_ui/includes/openlayers_ui.admin.inc \openlayers_ui_admin_settings()
  2. 7.2 modules/openlayers_ui/includes/openlayers_ui.admin.inc \openlayers_ui_admin_settings()

Menu callback; displays the openlayers module settings page.

See also

system_settings_form()

1 string reference to 'openlayers_ui_admin_settings'
openlayers_ui_menu in modules/openlayers_ui/openlayers_ui.module
Implements hook_menu().

File

modules/openlayers_ui/includes/openlayers_ui.admin.inc, line 14
This file holds the functions for the main openlayers Admin settings.

Code

function openlayers_ui_admin_settings($form, &$form_state) {
  $form['origin'] = array(
    '#type' => 'fieldset',
    '#title' => 'Library loading configuration',
  );
  $library = libraries_detect('openlayers3');
  $current_variant = \Drupal\openlayers\Config::get('openlayers.variant');
  if (!\Drupal\openlayers\Openlayers::detectLibrary()) {
    $current_variant = NULL;
  }
  $options_variants = array(
    '' => t('- Select the library variant -'),
  );
  foreach ($library['variants'] as $version => $variant) {
    list($optgroup) = explode(':', $version, 2);
    if (empty($optgroup)) {
      $optgroup = t('Other');
    }
    $optgroup = drupal_strtoupper($optgroup);
    $options_variants[$optgroup][$version] = isset($variant['name']) ? $variant['name'] : $version;
  }
  $form['origin']['variant'] = array(
    '#type' => 'select',
    '#title' => 'Select the Openlayers library variant to use.',
    '#options' => $options_variants,
    '#default_value' => $current_variant,
  );
  $form['origin']['debug'] = array(
    '#type' => 'checkbox',
    '#title' => 'Load javascript debug integration files ?',
    '#default_value' => \Drupal\openlayers\Config::get('openlayers.debug'),
  );
  $form['plugin-info'] = array(
    '#type' => 'fieldset',
    '#title' => 'Plugin information',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  foreach (\Drupal\openlayers\Openlayers::getPluginTypes() as $plugin_type) {
    $rows = array();
    $form['plugin-info'][$plugin_type . '-group'] = array(
      '#type' => 'fieldset',
      '#title' => $plugin_type,
      '#collapsed' => TRUE,
      '#collapsible' => TRUE,
    );
    foreach (\Drupal::service('openlayers.' . $plugin_type)
      ->getDefinitions() as $service => $definition) {
      $definition += array(
        'arguments' => array(
          'NULL',
        ),
      );
      list($module, $type, , $id) = explode('.', $service);
      $configuration = array(
        'name' => $definition['id'],
        'machine_name' => $definition['id'],
        'factory_service' => $module . '.' . $type . ':' . $id,
      );
      $instance = \Drupal\openlayers\Openlayers::load($plugin_type, $configuration);
      $attached = $instance
        ->attached();
      $sizes = array(
        'js' => 0,
        'css' => 0,
      );
      foreach (array_keys($sizes) as $size_type) {
        foreach ($attached[$size_type] as $data) {
          if (isset($data['type']) && $data['type'] != 'external') {
            if (!is_array($data['data'])) {
              $sizes[$size_type] += filesize($data['data']);
            }
          }
        }
      }
      foreach (array(
        'js',
        'css',
      ) as $file_type) {
        if (count($attached[$file_type]) != 0) {
          $sizes[$file_type] .= ' bytes.<br/>(' . count($attached[$file_type]);
          if (count($attached[$file_type]) == 1) {
            $sizes[$file_type] .= ' file)';
          }
          else {
            $sizes[$file_type] .= ' files)';
          }
        }
      }
      $class = array(
        'Class: ' . $definition['class'],
        'Classfile: ' . $instance
          ->getClassPath(),
      );
      $rows[] = array(
        $instance
          ->getProvider(),
        $instance
          ->getBaseId(),
        implode('<br/>', $class),
        implode('|', $definition['arguments']),
        $sizes['js'],
        $sizes['css'],
      );
    }
    $header = array(
      'Module provider',
      'ID',
      'Class',
      'Arguments',
      'JS size',
      'CSS size',
    );
    $table = theme('table', array(
      'header' => $header,
      'rows' => $rows,
      'empty' => t('No plugin available.'),
    ));
    $form['plugin-info'][$plugin_type . '-group']['table'] = array(
      '#markup' => $table,
    );
  }
  $form['buttons'] = array(
    'submit' => array(
      '#type' => 'submit',
      '#value' => 'Save configuration',
    ),
  );
  return $form;
}