WebformContentCreatorFieldMappingManager.php in Webform Content Creator 3.x
File
src/Plugin/WebformContentCreatorFieldMappingManager.php
View source
<?php
namespace Drupal\webform_content_creator\Plugin;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\webform_content_creator\FieldMappingInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
class WebformContentCreatorFieldMappingManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/WebformContentCreator/FieldMapping', $namespaces, $module_handler, 'Drupal\\webform_content_creator\\Plugin\\FieldMappingInterface', 'Drupal\\webform_content_creator\\Annotation\\WebformContentCreatorFieldMapping');
$this
->alterInfo('webform_content_creator_info');
$this
->setCacheBackend($cache_backend, 'webform_content_creator_info_plugins');
}
public function getPlugin($plugin_id = 'default_mapping') {
return $this
->createInstance($plugin_id);
}
public function getFieldMappings(string $field_type) {
$instances = $configuration = [];
$plugin_definitions = $this
->getDefinitions();
usort($plugin_definitions, function ($definition1, $definition2) {
return $definition1['weight'] <=> $definition1['weight'];
});
foreach ($this
->getDefinitions() as $field_mapping) {
if (in_array($field_type, $field_mapping['field_types']) || empty($field_mapping['field_types'])) {
$instances[] = $this
->createInstance($field_mapping['id'], $configuration)
->getPlugin();
}
}
return $instances;
}
}