FieldTypeExportManager.php in Entity Export CSV 8
File
src/Plugin/FieldTypeExportManager.php
View source
<?php
namespace Drupal\entity_export_csv\Plugin;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
class FieldTypeExportManager extends DefaultPluginManager implements FieldTypeExportManagerInterface {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/FieldTypeExport', $namespaces, $module_handler, 'Drupal\\entity_export_csv\\Plugin\\FieldTypeExportInterface', 'Drupal\\entity_export_csv\\Annotation\\FieldTypeExport');
$this
->alterInfo('entity_export_csv_field_type_export_info');
$this
->setCacheBackend($cache_backend, 'entity_export_csv_field_type_export_plugins');
}
public function getOptions() {
$options = [];
$definitions = $this
->getDefinitions();
$this
->sortDefinitions($definitions);
foreach ($definitions as $plugin_id => $definition) {
$options[$plugin_id] = $definition['label'];
}
return $options;
}
public function getFieldTypeOptions($field_type, $entity_type = NULL, $bundle = NULL, $field_name = NULL) {
$options = [];
$definitions = $this
->getDefinitions();
$this
->sortDefinitions($definitions);
foreach ($definitions as $plugin_id => $definition) {
if (!isset($definition['field_type'])) {
continue;
}
if (in_array($field_type, $definition['field_type']) || empty($definition['field_type'])) {
if ($entity_type) {
if (!empty($definition['entity_type']) && !in_array($entity_type, $definition['entity_type'])) {
continue;
}
}
if ($bundle) {
if (!empty($definition['bundle']) && !in_array($bundle, $definition['bundle'])) {
continue;
}
}
if ($field_name) {
if (!empty($definition['field_name']) && !in_array($field_name, $definition['field_name'])) {
continue;
}
}
if (isset($definition['exclusive']) && $definition['exclusive'] === TRUE) {
return [
$plugin_id => $definition['label'],
];
}
$options[$plugin_id] = $definition['label'];
}
}
return $options;
}
public function removeExcludeDefinitions(array $definitions) {
$definitions = isset($definitions) ? $definitions : $this
->getDefinitions();
unset($definitions['broken']);
return $definitions;
}
public function getFallbackPluginId($plugin_id, array $configuration = []) {
return 'broken';
}
protected function sortDefinitions(array &$definitions) {
uasort($definitions, function ($a, $b) {
return $a['weight'] - $b['weight'];
});
}
}