You are here

GeocoderPluginManagerBase.php in Geocoder 8.3

Same filename and directory in other branches
  1. 8.2 src/GeocoderPluginManagerBase.php

Namespace

Drupal\geocoder

File

src/GeocoderPluginManagerBase.php
View source
<?php

namespace Drupal\geocoder;

use Drupal\Core\Plugin\DefaultPluginManager;

/**
 * Provides a base class for geocoder plugin managers.
 */
abstract class GeocoderPluginManagerBase extends DefaultPluginManager {

  /**
   * List of fields types available as source for Geocode operations.
   *
   * @var array
   */
  protected $geocodeSourceFieldsTypes = [
    'string',
    'string_long',
    'text',
    'text_long',
    'text_with_summary',
  ];

  /**
   * List of fields types available as source for Reverse Geocode operations.
   *
   * @var array
   */
  protected $reverseGeocodeSourceFieldsTypes = [
    'geofield',
  ];

  /**
   * Gets a list of available plugins to be used in forms.
   *
   * @return string[]
   *   A list of plugins in a format suitable for form API '#options' key.
   */
  public function getPluginsAsOptions() : array {
    return array_map(function ($plugin) {
      return $plugin['name'];
    }, $this
      ->getPlugins());
  }

  /**
   * Return the array of plugins and their settings if any.
   *
   * @return array
   *   A list of plugins with their settings.
   */
  public function getPlugins() : array {
    $definitions = array_map(function (array $definition) {
      $definition += [
        'name' => $definition['id'],
      ];
      return $definition;
    }, $this
      ->getDefinitions());
    ksort($definitions);
    return $definitions;
  }

  /**
   * Gets a list of fields types available for Geocode operations.
   *
   * @return string[]
   *   A list of plugins in a format suitable for form API '#options' key.
   */
  public function getGeocodeSourceFieldsTypes() : array {
    return $this->geocodeSourceFieldsTypes;
  }

  /**
   * Gets a list of fields types available for Reverse Geocode operations.
   *
   * @return string[]
   *   A list of plugins in a format suitable for form API '#options' key.
   */
  public function getReverseGeocodeSourceFieldsTypes() : array {
    return $this->reverseGeocodeSourceFieldsTypes;
  }

}

Classes

Namesort descending Description
GeocoderPluginManagerBase Provides a base class for geocoder plugin managers.