You are here

FixedCoordinates.php in Geolocation Field 8.3

Same filename and directory in other branches
  1. 8.2 src/Plugin/geolocation/Location/FixedCoordinates.php

File

src/Plugin/geolocation/Location/FixedCoordinates.php
View source
<?php

namespace Drupal\geolocation\Plugin\geolocation\Location;

use Drupal\geolocation\LocationInterface;
use Drupal\geolocation\LocationBase;

/**
 * Fixed coordinates map center.
 *
 * PluginID for compatibility with v1.
 *
 * @Location(
 *   id = "fixed_value",
 *   name = @Translation("Fixed coordinates"),
 *   description = @Translation("Use preset fixed values as center."),
 * )
 */
class FixedCoordinates extends LocationBase implements LocationInterface {

  /**
   * {@inheritdoc}
   */
  public static function getDefaultSettings() {
    return [
      'latitude' => '',
      'longitude' => '',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getSettingsForm($option_id = NULL, array $settings = [], $context = NULL) {
    $settings = $this
      ->getSettings($settings);
    $form = [
      'latitude' => [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Latitude'),
        '#default_value' => $settings['latitude'],
        '#size' => 60,
        '#maxlength' => 128,
      ],
      'longitude' => [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Longitude'),
        '#default_value' => $settings['longitude'],
        '#size' => 60,
        '#maxlength' => 128,
      ],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function getCoordinates($center_option_id, array $center_option_settings, $context = NULL) {
    $settings = $this
      ->getSettings($center_option_settings);
    return [
      'lat' => (double) $settings['latitude'],
      'lng' => (double) $settings['longitude'],
    ];
  }

}

Classes

Namesort descending Description
FixedCoordinates Fixed coordinates map center.