abstract class DataProviderBase in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 src/DataProviderBase.php \Drupal\geolocation\DataProviderBase
Class DataProviderBase.
@package Drupal\geolocation
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\geolocation\DataProviderBase implements ContainerFactoryPluginInterface, DataProviderInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of DataProviderBase
4 files declare their use of DataProviderBase
- AddressFieldProvider.php in modules/
geolocation_address/ src/ Plugin/ geolocation/ DataProvider/ AddressFieldProvider.php - Geofield.php in modules/
geolocation_geofield/ src/ Plugin/ geolocation/ DataProvider/ Geofield.php - GeolocationFieldProvider.php in src/
Plugin/ geolocation/ DataProvider/ GeolocationFieldProvider.php - SearchAPI.php in modules/
geolocation_search_api/ src/ Plugin/ geolocation/ DataProvider/ SearchAPI.php
File
- src/
DataProviderBase.php, line 21
Namespace
Drupal\geolocationView source
abstract class DataProviderBase extends PluginBase implements DataProviderInterface, ContainerFactoryPluginInterface {
/**
* Entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Views field.
*
* @var \Drupal\views\Plugin\views\field\FieldPluginBase
*/
protected $viewsField;
/**
* Field definition.
*
* @var \Drupal\Core\Field\FieldDefinitionInterface
*/
protected $fieldDefinition;
/**
* Constructs a new GeocoderBase 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.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* Entity type manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManagerInterface $entity_field_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityFieldManager = $entity_field_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_field.manager'));
}
/**
* {@inheritdoc}
*/
public function getTokenHelp(FieldDefinitionInterface $fieldDefinition = NULL) {
if (empty($fieldDefinition)) {
$fieldDefinition = $this->fieldDefinition;
}
$element = [];
$element['token_items'] = [
'#type' => 'table',
'#prefix' => '<h4>' . $this
->t('Geolocation Item Tokens') . '</h4>',
'#header' => [
$this
->t('Token'),
$this
->t('Description'),
],
];
foreach ($fieldDefinition
->getFieldStorageDefinition()
->getColumns() as $id => $column) {
$item = [
'token' => [
'#plain_text' => '[geolocation_current_item:' . $id . ']',
],
];
if (!empty($column['description'])) {
$item['description'] = [
'#plain_text' => $column['description'],
];
}
$element['token_items'][] = $item;
}
if (\Drupal::service('module_handler')
->moduleExists('token') && method_exists($fieldDefinition, 'getTargetEntityTypeId')) {
// Add the token UI from the token module if present.
$element['token_help'] = [
'#theme' => 'token_tree_link',
'#prefix' => '<h4>' . $this
->t('Additional Tokens') . '</h4>',
'#token_types' => [
$fieldDefinition
->getTargetEntityTypeId(),
],
'#weight' => 100,
];
}
return $element;
}
/**
* {@inheritdoc}
*/
public function replaceFieldItemTokens($text, FieldItemInterface $fieldItem) {
$token_context['geolocation_current_item'] = $fieldItem;
$entity = NULL;
try {
$entity = $fieldItem
->getParent()
->getParent()
->getValue();
} catch (\Exception $e) {
}
if (is_object($entity) && $entity instanceof ContentEntityInterface) {
$token_context[$entity
->getEntityTypeId()] = $entity;
}
$text = \Drupal::token()
->replace($text, $token_context, [
'callback' => [
$this,
'fieldItemTokens',
],
'clear' => TRUE,
]);
$text = Html::decodeEntities($text);
return $text;
}
/**
* Token replacement support function, callback to token replacement function.
*
* @param array $replacements
* An associative array variable containing mappings from token names to
* values (for use with strtr()).
* @param array $data
* Current item replacements.
* @param array $options
* A keyed array of settings and flags to control the token replacement
* process. See \Drupal\Core\Utility\Token::replace().
*/
public function fieldItemTokens(array &$replacements, array $data, array $options) {
if (isset($data['geolocation_current_item'])) {
/** @var \Drupal\Core\Field\FieldItemInterface $item */
$item = $data['geolocation_current_item'];
foreach ($this->fieldDefinition
->getFieldStorageDefinition()
->getColumns() as $id => $column) {
if ($item
->get($id) && isset($replacements['[geolocation_current_item:' . $id . ']'])) {
$replacements['[geolocation_current_item:' . $id . ']'] = $item
->get($id)
->getValue();
}
}
}
}
/**
* {@inheritdoc}
*/
public function isViewsGeoOption(FieldPluginBase $viewsField) {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getPositionsFromViewsRow(ResultRow $row, FieldPluginBase $viewsField = NULL) {
if (empty($viewsField)) {
$viewsField = $this->viewsField;
}
$positions = [];
$entity = $viewsField
->getEntity($row);
if (isset($entity->{$viewsField->definition['field_name']})) {
/** @var \Drupal\Core\Field\FieldItemListInterface $geo_items */
$geo_items = $entity->{$viewsField->definition['field_name']};
foreach ($geo_items as $item) {
$positions[] = $this
->getPositionsFromItem($item);
}
}
return $positions;
}
/**
* {@inheritdoc}
*/
public function setViewsField(FieldPluginBase $viewsField) {
$this->viewsField = $viewsField;
}
/**
* {@inheritdoc}
*/
public function setFieldDefinition(FieldDefinitionInterface $fieldDefinition) {
$this->fieldDefinition = $fieldDefinition;
}
/**
* {@inheritdoc}
*/
public function getPositionsFromItem(FieldItemInterface $fieldItem) {
return [];
}
/**
* {@inheritdoc}
*/
public function getSettingsForm(array $settings, array $parents = []) {
return [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DataProviderBase:: |
protected | property | Entity field manager. | |
DataProviderBase:: |
protected | property | Field definition. | |
DataProviderBase:: |
protected | property | Views field. | |
DataProviderBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
DataProviderBase:: |
public | function | Token replacement support function, callback to token replacement function. | |
DataProviderBase:: |
public | function |
Get positions from field item list. Overrides DataProviderInterface:: |
3 |
DataProviderBase:: |
public | function |
Get positions from views row. Overrides DataProviderInterface:: |
1 |
DataProviderBase:: |
public | function |
Provide data provider settings form array. Overrides DataProviderInterface:: |
1 |
DataProviderBase:: |
public | function |
Return field item tokens. Overrides DataProviderInterface:: |
1 |
DataProviderBase:: |
public | function |
Determine valid views option. Overrides DataProviderInterface:: |
4 |
DataProviderBase:: |
public | function |
Replace field item tokens. Overrides DataProviderInterface:: |
1 |
DataProviderBase:: |
public | function |
Set field definition. Overrides DataProviderInterface:: |
|
DataProviderBase:: |
public | function |
Set views field. Overrides DataProviderInterface:: |
|
DataProviderBase:: |
public | function |
Constructs a new GeocoderBase object. Overrides PluginBase:: |
1 |
DataProviderInterface:: |
public | function | Determine valid field geo option. | 4 |
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 | |
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. | |
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. |