UserRestrictionTypeManager.php in User restrictions 8        
                          
                  
                        
  
  
  
  
  
File
  src/UserRestrictionTypeManager.php
  
    View source  
  <?php
namespace Drupal\user_restrictions;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
class UserRestrictionTypeManager extends DefaultPluginManager implements UserRestrictionTypeManagerInterface {
  
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
    parent::__construct('Plugin/UserRestrictionType', $namespaces, $module_handler, 'Drupal\\user_restrictions\\Plugin\\UserRestrictionTypeInterface', 'Drupal\\user_restrictions\\Annotation\\UserRestrictionType');
    $this
      ->alterInfo('user_restriction_type_info');
    $this
      ->setCacheBackend($cache_backend, 'user_restriction_type_plugins');
  }
  
  public function getTypes() {
    $instances =& drupal_static(__FUNCTION__, []);
    if (empty($instances)) {
      
      $plugins = $this
        ->getDefinitions();
      
      uasort($plugins, [
        'Drupal\\Component\\Utility\\SortArray',
        'sortByWeightElement',
      ]);
      foreach ($plugins as $plugin_id => $plugin) {
        
        $instances[$plugin_id] = $this
          ->createInstance($plugin_id, $plugin);
      }
    }
    return $instances;
  }
  
  public function getType($id) {
    $instances = $this
      ->getTypes();
    return $instances[$id];
  }
  
  public function getTypesAsOptions() {
    $options = [];
    foreach ($this
      ->getTypes() as $plugin_id => $type) {
      $options[$plugin_id] = $type
        ->getLabel();
    }
    return $options;
  }
}