class ManualOriginDefault in Geofield 8
Defines 'Geofield Manual Origin' plugin.
@package Drupal\geofield\Plugin
Plugin annotation
@GeofieldProximitySource(
id = "geofield_manual_origin",
label = @Translation("Manual Origin (Default)"),
description = @Translation("Allow the Manual input of Distance and Origin (as couple of Latitude and Longitude in decimal degrees.)"),
exposedDescription = @Translation("Manual input of Distance and Origin (as couple of Latitude and Longitude in decimal degrees.)"),
context = {},
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\geofield\Plugin\GeofieldProximitySourceBase implements GeofieldProximitySourceInterface uses StringTranslationTrait
- class \Drupal\geofield\Plugin\GeofieldProximitySource\ManualOriginDefault
- class \Drupal\geofield\Plugin\GeofieldProximitySourceBase implements GeofieldProximitySourceInterface uses StringTranslationTrait
Expanded class hierarchy of ManualOriginDefault
File
- src/
Plugin/ GeofieldProximitySource/ ManualOriginDefault.php, line 22
Namespace
Drupal\geofield\Plugin\GeofieldProximitySourceView source
class ManualOriginDefault extends GeofieldProximitySourceBase {
/**
* Constructs a ManualOriginDefault object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->origin['lat'] = isset($configuration['origin']) && is_numeric($configuration['origin']['lat']) ? $configuration['origin']['lat'] : '';
$this->origin['lon'] = isset($configuration['origin']) && is_numeric($configuration['origin']['lon']) ? $configuration['origin']['lon'] : '';
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(array &$form, FormStateInterface $form_state, array $options_parents, $is_exposed = FALSE) {
$lat = isset($this->configuration['origin']['lat']) ? $this->configuration['origin']['lat'] : $this->origin['lat'];
$lon = isset($this->configuration['origin']['lon']) ? $this->configuration['origin']['lon'] : $this->origin['lon'];
$form["origin"] = [
'#title' => $this
->t('Origin Coordinates'),
'#type' => 'geofield_latlon',
'#description' => $this
->t('Value in decimal degrees. Use dot (.) as decimal separator.'),
'#default_value' => [
'lat' => $lat,
'lon' => $lon,
],
];
// If it is a proximity filter context and IS NOT exposed, render origin
// hidden and origin_summary options.
if ($this->viewHandler->configuration['id'] == 'geofield_proximity_filter' && !$is_exposed) {
$form['origin_hidden_flag'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Hide the Origin Input elements from the Exposed Form'),
'#default_value' => isset($this->configuration['origin_hidden_flag']) ? $this->configuration['origin_hidden_flag'] : FALSE,
'#states' => [
'visible' => [
':input[name="options[expose_button][checkbox][checkbox]"]' => [
'checked' => TRUE,
],
],
],
];
$form['origin_summary_flag'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show (anyway) the Origin coordinates as summary in the Exposed Form'),
'#default_value' => isset($this->configuration['origin_summary_flag']) ? $this->configuration['origin_summary_flag'] : TRUE,
'#states' => [
'visible' => [
':input[name="options[source_configuration][origin_hidden_flag]"]' => [
'checked' => TRUE,
],
],
],
];
}
// If it IS exposed, eventually Hide the Origin components..
if ($is_exposed && (isset($this->configuration['origin_hidden_flag']) && $this->configuration['origin_hidden_flag'])) {
$form["origin"]['#attributes']['class'][] = 'visually-hidden';
// Eventually Render the Origin Summary.
if (isset($this->configuration['origin_summary_flag']) && $this->configuration['origin_summary_flag']) {
$form['origin_summary'] = [
"#type" => 'html_tag',
"#tag" => 'div',
'#value' => $this
->t('from Latitude: @lat and Longitude: @lon.', [
'@lat' => new FormattableMarkup('<span class="geofield-lat"> @lat</span>', [
'@lat' => $lat,
]),
'@lon' => new FormattableMarkup('<span class="geofield-lon"> @lon</span>', [
'@lon' => $lon,
]),
]),
'#attributes' => [
'class' => [
'proximity-origin-summary',
],
],
];
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GeofieldProximitySourceBase:: |
protected | property | The origin point to measure proximity from. | |
GeofieldProximitySourceBase:: |
protected | property | The name of the constant defining the measurement unit. | |
GeofieldProximitySourceBase:: |
protected | property | The view handler which uses this proximity plugin. | |
GeofieldProximitySourceBase:: |
public | function |
Gets the haversine options. Overrides GeofieldProximitySourceInterface:: |
|
GeofieldProximitySourceBase:: |
public | function |
Gets the proximity distance origin. Overrides GeofieldProximitySourceInterface:: |
2 |
GeofieldProximitySourceBase:: |
public | function |
Get the calculated proximity. Overrides GeofieldProximitySourceInterface:: |
|
GeofieldProximitySourceBase:: |
public | function |
Get the current units. Overrides GeofieldProximitySourceInterface:: |
|
GeofieldProximitySourceBase:: |
public | function | Get the list of valid options for units. | |
GeofieldProximitySourceBase:: |
public | function |
Check if Location is empty. Overrides GeofieldProximitySourceInterface:: |
|
GeofieldProximitySourceBase:: |
public | function |
Check for a valid couple of latitude and longitude. Overrides GeofieldProximitySourceInterface:: |
|
GeofieldProximitySourceBase:: |
public | function |
Sets the proximity distance origin. Overrides GeofieldProximitySourceInterface:: |
|
GeofieldProximitySourceBase:: |
public | function |
Set the units to perform the calculation in. Overrides GeofieldProximitySourceInterface:: |
|
GeofieldProximitySourceBase:: |
public | function |
Sets view handler which uses this proximity plugin. Overrides GeofieldProximitySourceInterface:: |
|
GeofieldProximitySourceBase:: |
public | function |
Validates the options form for the geofield proximity plugin. Overrides GeofieldProximitySourceInterface:: |
1 |
ManualOriginDefault:: |
public | function |
Builds the specific form elements for the geofield proximity plugin. Overrides GeofieldProximitySourceBase:: |
1 |
ManualOriginDefault:: |
public | function |
Constructs a ManualOriginDefault object. Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |