public function PreprocessorPluginManager::preprocess in Geocoder 8.3
Same name and namespace in other branches
- 8.2 modules/geocoder_field/src/PreprocessorPluginManager.php \Drupal\geocoder_field\PreprocessorPluginManager::preprocess()
Pre-processes a field, running all plugins that support that field type.
Parameters
\Drupal\Core\Field\FieldItemListInterface $field: The field item list to be processed.
Throws
\Drupal\Component\Plugin\Exception\PluginException If the instance cannot be created, such as if the ID is invalid.
File
- modules/
geocoder_field/ src/ PreprocessorPluginManager.php, line 37
Class
- PreprocessorPluginManager
- Provides a plugin manager for geocoder data preprocessors.
Namespace
Drupal\geocoder_fieldCode
public function preprocess(FieldItemListInterface &$field) {
$type = $field
->getFieldDefinition()
->getType();
// Get a list of plugins that are supporting fields of type $type.
$definitions = array_filter($this
->getDefinitions(), function ($definition) use ($type) {
return in_array($type, $definition['field_types']);
});
// Sort definitions by 'weight'.
uasort($definitions, [
SortArray::class,
'sortByWeightElement',
]);
foreach ($definitions as $plugin_id => $definition) {
/** @var \Drupal\geocoder_field\PreprocessorInterface $preprocessor */
$preprocessor = $this
->createInstance($plugin_id);
$preprocessor
->setField($field)
->preprocess();
}
}