Manager.php in Field Permissions 8
File
src/Plugin/FieldPermissionType/Manager.php
View source
<?php
namespace Drupal\field_permissions\Plugin\FieldPermissionType;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\field_permissions\Annotation\FieldPermissionType;
use Drupal\field_permissions\Plugin\FieldPermissionTypeInterface;
class Manager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/FieldPermissionType', $namespaces, $module_handler, FieldPermissionTypeInterface::class, FieldPermissionType::class);
$this
->setCacheBackend($cache_backend, 'field_permission_type_plugins');
$this
->alterInfo('field_permission_type_plugin');
}
public function createInstance($plugin_id, array $configuration = [], FieldStorageConfigInterface $field_storage = NULL) {
$plugin_definition = $this
->getDefinition($plugin_id);
$plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
if (is_subclass_of($plugin_class, ContainerFactoryPluginInterface::class)) {
$plugin = $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition, $field_storage);
}
else {
$plugin = new $plugin_class($configuration, $plugin_id, $plugin_definition, $field_storage);
}
return $plugin;
}
public function getDefinitions() {
$definitions = parent::getDefinitions();
uasort($definitions, function ($a, $b) {
if ($a['weight'] == $b['weight']) {
return 0;
}
return $a['weight'] < $b['weight'] ? -1 : 1;
});
return $definitions;
}
}
Classes
Name |
Description |
Manager |
Field permission type plugin manager. |