You are here

public function GeolocationMapFormatterBase::__construct in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/GeolocationMapFormatterBase.php \Drupal\geolocation\Plugin\Field\FieldFormatter\GeolocationMapFormatterBase::__construct()

Constructs a FormatterBase object.

Parameters

string $plugin_id: The plugin_id for the formatter.

mixed $plugin_definition: The plugin implementation definition.

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The definition of the field to which the formatter is associated.

array $settings: The formatter settings.

string $label: The formatter label display setting.

string $view_mode: The view mode.

array $third_party_settings: Any third party settings.

Overrides FormatterBase::__construct

File

src/Plugin/Field/FieldFormatter/GeolocationMapFormatterBase.php, line 57

Class

GeolocationMapFormatterBase
Plugin base for Map based formatters.

Namespace

Drupal\geolocation\Plugin\Field\FieldFormatter

Code

public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings) {
  parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
  $settings = $this
    ->getSettings();
  $this->mapProviderManager = \Drupal::service('plugin.manager.geolocation.mapprovider');
  $this->mapCenterManager = \Drupal::service('plugin.manager.geolocation.mapcenter');
  if (!empty($settings['map_provider_id'])) {
    $this->mapProvider = $this->mapProviderManager
      ->getMapProvider($settings['map_provider_id'], $settings['map_provider_settings']);
  }
  $this->dataProvider = \Drupal::service('plugin.manager.geolocation.dataprovider')
    ->createInstance(static::$dataProviderId, $settings['data_provider_settings']);
  if (empty($this->dataProvider)) {
    throw new \Exception('Geolocation data provider not found');
  }
  $this->dataProvider
    ->setFieldDefinition($field_definition);
}