class GeoCodeAddressBlock in IP Geolocation Views & Maps 8
IPGV&M: Set my location .
Plugin annotation
@Block(
id = "geocode_address",
admin_label = @Translation("IPGV&M: Set my location"),
category = @Translation("IP Geoloc"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Component\Plugin\ContextAwarePluginBase implements ContextAwarePluginInterface
- class \Drupal\Core\Plugin\ContextAwarePluginBase implements CacheableDependencyInterface, ContextAwarePluginInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\Core\Block\BlockBase implements BlockPluginInterface, PluginWithFormsInterface, PreviewFallbackInterface uses BlockPluginTrait, ContextAwarePluginAssignmentTrait
- class \Drupal\ip_geoloc\Plugin\Block\GeoCodeAddressBlock
- class \Drupal\Core\Block\BlockBase implements BlockPluginInterface, PluginWithFormsInterface, PreviewFallbackInterface uses BlockPluginTrait, ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Plugin\ContextAwarePluginBase implements CacheableDependencyInterface, ContextAwarePluginInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\Component\Plugin\ContextAwarePluginBase implements ContextAwarePluginInterface
Expanded class hierarchy of GeoCodeAddressBlock
File
- src/
Plugin/ Block/ GeoCodeAddressBlock.php, line 21
Namespace
Drupal\ip_geoloc\Plugin\BlockView source
class GeoCodeAddressBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
// Calling the set location form in block.
$form = $this->formBuilder
->getForm(SetLocationForm::class);
return $form;
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return 0;
}
/**
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface &$form_state) {
$form = parent::blockForm($form, $form_state);
// Retrieve existing configuration for this block.
$config = $this
->getConfiguration();
// Add fields for block configuration.
$form['address'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Visitor location'),
'#description' => $this
->t('This panel offers various ways for the visitor to set the focus of maps created through this module.'),
];
$note = $this
->t('As soon as the newly updated visitor location comes in, this is reflected on the page through an automatic refresh, unless the auto-refresh has been switched off under <a href="!url">Advanced options</a>.', [
'!url' => url('admin/config/system/ip_geoloc'),
]);
$form['address']['find_visitor'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#title' => $this
->t('"Find me" button'),
'#description' => $this
->t("Displays a button for the visitor to put themselves on the map. If they confirm the browser prompt, this locates the visitor via their device's WiFi and GPS capabilities. This typcially takes 3 seconds.") . ' ' . $note,
];
$form['address']['find_visitor']['ip_geoloc_visitor_find'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Find visitor using Wifi/GPS location detection'),
'#default_value' => $config
->get('ip_geoloc_visitor_find') ? $config
->get('ip_geoloc_visitor_find') : TRUE,
];
$form['address']['find_visitor']['ip_geoloc_visitor_reverse_geocode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Reverse-geocode visitor location to a street address'),
'#default_value' => $config
->get('ip_geoloc_visitor_reverse_geocode') ? $config
->get('ip_geoloc_visitor_reverse_geocode') : TRUE,
'#description' => $this
->t('If ticked, reverse-geocoding is executed immeditaley after the visitor position is detected, as part of the same request. It typically adds another 0.3 seconds of waiting time.'),
'#states' => [
'visible' => [
'input[name="ip_geoloc_visitor_find"]' => [
'checked' => TRUE,
],
],
],
];
$form['address']['find_visitor']['ip_geoloc_visitor_find_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label for "Find me" button'),
'#size' => 30,
'#default_value' => Xss::filterAdmin($config
->get('ip_geoloc_visitor_find_label') ? $config
->get('ip_geoloc_visitor_find_label') : ''),
'#description' => $this
->t('Defaults to %default <br/>You may use most HTML tags.', [
'%default' => IP_GEOLOC_VISITOR_DEFAULT_FIND_LABEL,
]),
'#states' => [
'visible' => [
'input[name="ip_geoloc_visitor_find"]' => [
'checked' => TRUE,
],
],
],
];
$form['address']['find_visitor']['ip_geoloc_visitor_find_position'] = [
'#type' => 'select',
'#title' => $this
->t('Position of "Find me" button'),
// Keys represent form element weights.
'#options' => [
0 => $this
->t('First'),
7 => $this
->t('Second'),
12 => $this
->t('2nd Last'),
17 => $this
->t('Last'),
],
'#default_value' => $config
->get('ip_geoloc_visitor_find_position') ? $config
->get('ip_geoloc_visitor_find_position') : 0,
'#description' => $this
->t('Relative to the other buttons on the "Set my location" form, if present. These buttons can be configured below.'),
'#states' => [
'visible' => [
'input[name="ip_geoloc_visitor_find"]' => [
'checked' => TRUE,
],
],
],
];
$throbber_text = $config
->get('ip_geoloc_throbber_text') ? $config
->get('ip_geoloc_throbber_text') : '';
$form['address']['find_visitor']['ip_geoloc_throbber_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Text displayed while visitor is being geolocated'),
'#size' => 30,
'#default_value' => $throbber_text == '<none>' ? $throbber_text : Xss::filterAdmin($throbber_text),
'#description' => $this
->t('A text shown together with an animated image, aka throbber, to show the visitor that geolocation is in progress. </br/>Defaults to %default <br/>You may use most HTML tags. Use <em><none></em> to have no throbber and no text.', [
'%default' => IP_GEOLOC_THROBBER_DEFAULT_TEXT,
]),
'#states' => [
'visible' => [
'input[name="ip_geoloc_visitor_find"]' => [
'checked' => TRUE,
],
],
],
];
$form['address']['edit'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => $this
->t('"Move to" option with editable location'),
];
$form['address']['edit']['ip_geoloc_visitor_address_editable'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Make address editable'),
'#default_value' => $config
->get('ip_geoloc_visitor_address_editable') ? $config
->get('ip_geoloc_visitor_address_editable') : TRUE,
'#description' => $this
->t('If ticked, the visitor may enter a new address or tweak their reverse-geocoded address. It will be geocoded to latitude & longitude to become their new location.<br/>If not ticked, then this field simply displays the current reverse-geocoded address, without a submit button.'),
];
$label = $config
->get('ip_geoloc_visitor_address_label') ? $config
->get('ip_geoloc_visitor_address_label') : '';
$form['address']['edit']['ip_geoloc_visitor_address_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label for editable address'),
'#size' => 30,
'#default_value' => $label == '<none>' ? $label : Xss::filterAdmin($label),
'#description' => $this
->t('Defaults to %default. You may use most HTML tags. Use <em><none></em> for no label.', [
'%default' => IP_GEOLOC_VISITOR_DEFAULT_ADDRESS_LABEL,
]),
'#states' => [
'visible' => [
'input[name="ip_geoloc_visitor_address_editable"]' => [
'checked' => TRUE,
],
],
],
];
$form['address']['display'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => $this
->t('Form element to enter and display address'),
];
$form['address']['display']['ip_geoloc_address_element'] = [
'#type' => 'radios',
'#options' => [
0 => $this
->t('text field'),
1 => $this
->t('text area, 1 line'),
2 => $this
->t('text area, 2 lines'),
3 => $this
->t('text area, 3 lines'),
],
'#default_value' => $config
->get('ip_geoloc_address_element') ? $config
->get('ip_geoloc_address_element') : 2,
'#description' => $this
->t('Text areas may be resized by the visitor, text fields cannot.'),
];
$form['address']['display']['ip_geoloc_visitor_address_default'] = [
'#type' => 'textarea',
'#rows' => 2,
'#title' => $this
->t('Default partial address'),
'#default_value' => Html::escape($config
->get('ip_geoloc_visitor_address_default') ? $config
->get('ip_geoloc_visitor_address_default') : ''),
'#description' => $this
->t("You may use this to pre-populate the visitor address box with, say, a country, so that the visitor and the geocoding service have a context to the partial address entered. You may use comma's, newlines and blank lines if you wish."),
];
$vocabularies = [];
foreach (Vocabulary::loadMultiple() as $vid => $vocabulary) {
// TODO find replacement field_info_instances for D8
/*
foreach (field_info_instances('taxonomy_term', $vocabulary->machine_name) as $field_name => $field) {
$field_info = field_info_field($field_name);
if ($field_info['type'] == 'geofield') {
$vocabularies[$vid] = $vocabulary->label();
break;
}
}
*/
}
$description = $this
->t('The region selector allows the visitor to zoom in on a geographical area, such as a province or wine region, picked from a taxonomy vocabulary. The vocabulary must have a <a target="geofield" href="@url">Geofield</a> attached, providing the latitude & longitude of the centre of the region.', [
'@url' => url('http://drupal.org/project/geofield'),
]);
$form['address']['region'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => $this
->t('Geographical region selector'),
'#description' => $description,
];
$form['address']['region']['ip_geoloc_geo_vocabulary_id'] = [
'#type' => 'select',
'#options' => [
0 => $this
->t('None'),
] + $vocabularies,
'#default_value' => $config
->get('ip_geoloc_geo_vocabulary_id') ? $config
->get('ip_geoloc_geo_vocabulary_id') : 0,
];
if (empty($vocabularies)) {
$form['address']['region']['ip_geoloc_geo_vocabulary_id']['#description'] = $this
->t('You do not appear to have any vocabularies on which a Geofield is defined. You cannot enable this feature until you do.');
}
$form['address']['region']['ip_geoloc_region_autocomplete'] = [
'#type' => 'select',
'#title' => $this
->t('Widget to select geographical region'),
'#options' => [
'0' => $this
->t('Select (drop-down)'),
'1' => $this
->t('Autocomplete textfield'),
],
'#default_value' => $config
->get('ip_geoloc_region_autocomplete') ? $config
->get('ip_geoloc_region_autocomplete') : '0',
'#states' => [
'invisible' => [
'select[name="ip_geoloc_geo_vocabulary_id"]' => [
'value' => '0',
],
],
],
];
$label = $config
->get('ip_geoloc_visitor_region_label') ? $config
->get('ip_geoloc_visitor_region_label') : '';
$form['address']['region']['ip_geoloc_visitor_region_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label for region selector'),
'#size' => 30,
'#default_value' => $label == '<none>' ? $label : Xss::filterAdmin($label),
'#description' => $this
->t('Defaults to %default. You may use most HTML tags. Use <em><none></em> for no label.', [
'%default' => IP_GEOLOC_VISITOR_DEFAULT_REGION_LABEL,
]),
'#states' => [
'invisible' => [
'select[name="ip_geoloc_geo_vocabulary_id"]' => [
'value' => 0,
],
],
],
];
$form['address']['region']['ip_geoloc_region_parent'] = [
'#type' => 'select',
'#title' => $this
->t('Center to use'),
'#options' => [
'0' => $this
->t('Selected region'),
'1' => $this
->t('Parent of selected region'),
'2' => $this
->t('Grandparent of selected region'),
'3' => $this
->t('Great-grandparent of selected region'),
],
'#default_value' => $config
->get('ip_geoloc_region_parent') ? $config
->get('ip_geoloc_region_parent') : 0,
'#description' => $this
->t('If the selected parent does not exist the next parent up will be used instead.'),
'#states' => [
'invisible' => [
'select[name="ip_geoloc_geo_vocabulary_id"]' => [
'value' => '0',
],
],
],
];
$form['redirection'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => $this
->t('Redirection'),
'#description' => $this
->t('Redirection'),
];
global $base_url;
$form['redirection']['ip_geoloc_address_redirect'] = [
'#type' => 'textfield',
'#field_prefix' => "{$base_url}/",
'#title' => $this
->t('Redirect upon submit'),
'#default_value' => $config
->get('ip_geoloc_address_redirect') ? $config
->get('ip_geoloc_address_redirect') : '',
'#description' => $this
->t('The page to redirect to after the user has pressed "Go". Use <em><front></em> for the front page.'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface &$form_state) {
// Migration comment: Part of ip_geoloc_block_save for geocode_address delta.
foreach ($form_state
->getValues() as $variable => $value) {
if (strpos($variable, 'ip_geoloc') === 0) {
$this->configuration[$variable] = $value;
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockPluginInterface:: |
constant | Indicates the block label (title) should be displayed to end users. | ||
BlockPluginTrait:: |
protected | property | The transliteration service. | |
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
protected | function | Returns generic default configuration for block plugins. | |
BlockPluginTrait:: |
protected | function | Indicates whether the block should be shown. | 16 |
BlockPluginTrait:: |
public | function | 3 | |
BlockPluginTrait:: |
public | function | Creates a generic configuration form for all block types. Individual block plugins can add elements to this form by overriding BlockBase::blockForm(). Most block plugins should not override this method unless they need to alter the generic form elements. | 2 |
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | 19 | |
BlockPluginTrait:: |
public | function | 1 | |
BlockPluginTrait:: |
public | function | 1 | |
BlockPluginTrait:: |
public | function | 3 | |
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | Sets the transliteration service. | |
BlockPluginTrait:: |
public | function | Most block plugins should not override this method. To add submission handling for a specific block type, override BlockBase::blockSubmit(). | |
BlockPluginTrait:: |
protected | function | Wraps the transliteration service. | |
BlockPluginTrait:: |
public | function | Most block plugins should not override this method. To add validation for a specific block type, override BlockBase::blockValidate(). | 1 |
BlockPluginTrait:: |
public | function | 22 | |
ContextAwarePluginAssignmentTrait:: |
protected | function | Builds a form element for assigning a context to a given slot. | |
ContextAwarePluginAssignmentTrait:: |
protected | function | Wraps the context handler. | |
ContextAwarePluginBase:: |
protected | property | The data objects representing the context of this plugin. | |
ContextAwarePluginBase:: |
private | property | Data objects representing the contexts passed in the plugin configuration. | |
ContextAwarePluginBase:: |
protected | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
9 |
ContextAwarePluginBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
4 |
ContextAwarePluginBase:: |
public | function |
This code is identical to the Component in order to pick up a different
Context class. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Gets a mapping of the expected assignment names to their context names. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the value for a defined context. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the values for all defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Set a context on this plugin. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Sets a mapping of the expected assignment names to their context names. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Sets the value for a defined context. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Validates the set values for the defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function | Implements magic __get() method. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
GeoCodeAddressBlock:: |
public | function |
Overrides BlockPluginTrait:: |
|
GeoCodeAddressBlock:: |
public | function |
Overrides BlockPluginTrait:: |
|
GeoCodeAddressBlock:: |
public | function |
Builds and returns the renderable array for this block plugin. Overrides BlockPluginInterface:: |
|
GeoCodeAddressBlock:: |
public | function |
The maximum age for which this object may be cached. Overrides ContextAwarePluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
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. | |
PluginWithFormsTrait:: |
public | function | ||
PluginWithFormsTrait:: |
public | function | ||
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. | |
TypedDataTrait:: |
protected | property | The typed data manager used for creating the data types. | |
TypedDataTrait:: |
public | function | Gets the typed data manager. | 2 |
TypedDataTrait:: |
public | function | Sets the typed data manager. | 2 |