FieldStorageFormatManager.php in Apigee Edge 8
File
src/Plugin/FieldStorageFormatManager.php
View source
<?php
namespace Drupal\apigee_edge\Plugin;
use Drupal\apigee_edge\Annotation\ApigeeFieldStorageFormat;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
class FieldStorageFormatManager extends DefaultPluginManager implements FieldStorageFormatManagerInterface {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/ApigeeFieldStorageFormat', $namespaces, $module_handler, FieldStorageFormatInterface::class, ApigeeFieldStorageFormat::class);
$this
->alterInfo('apigee_field_storage_format_info');
$this
->setCacheBackend($cache, 'apigee_field_storage_format_plugins');
}
protected function findDefinitions() : array {
$definitions = parent::findDefinitions();
uasort($definitions, function (array $def0, array $def1) {
return ($def0['weight'] ?? 0) <=> ($def1['weight'] ?? 0);
});
return $definitions;
}
public function lookupPluginForFieldType(string $field_type) : ?FieldStorageFormatInterface {
$definitions = $this
->getDefinitions();
foreach ($definitions as $name => $definition) {
$fields = $definition['fields'] ?? [];
if (in_array($field_type, $fields) || in_array('*', $fields)) {
$instance = $this
->createInstance($name);
return $instance;
}
}
return NULL;
}
}