You are here

AcceptanceMethodPluginManager.php in Entity Legal 8

File

src/Plugin/AcceptanceMethodPluginManager.php
View source
<?php

/**
 * @file
 * Contains \Drupal\entity_legal\Plugin\AcceptanceMethodPluginManager.
 */
namespace Drupal\entity_legal\Plugin;

use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;

/**
 * Plugin type manager for acceptance methods.
 */
class AcceptanceMethodPluginManager extends DefaultPluginManager {

  /**
   * An array of formatter options for each field type.
   *
   * @var array
   */
  protected $formatterOptions;

  /**
   * The field type manager to define field.
   *
   * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
   */
  protected $fieldTypeManager;

  /**
   * Constructs a FormatterPluginManager object.
   *
   * @param \Traversable $namespaces
   *   An object that implements \Traversable which contains the root paths
   *   keyed by the corresponding namespace to look for plugin implementations.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
   *   Cache backend instance to use.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
   *   The 'field type' plugin manager.
   */
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
    parent::__construct('Plugin/EntityLegal/AcceptanceMethod', $namespaces, $module_handler, 'Drupal\\entity_legal\\AcceptanceMethod\\AcceptanceMethodInterface', 'Drupal\\entity_legal\\Annotation\\AcceptanceMethod');
    $this
      ->setCacheBackend($cache_backend, 'entity_legal_acceptance_method_plugins');

    //    $this->alterInfo('field_formatter_info');
    //    $this->fieldTypeManager = $field_type_manager;
  }

  /**
   * Get plugins only related to new users.
   *
   * @return array
   */
  public function getNewUserPlugins() {
    $new_user_plugins = array();
    $definitions = $this
      ->getDefinitions();
    foreach ($definitions as $plugin_name => $plugin_definition) {
      if (!empty($plugin_definition['new_users'])) {
        $new_user_plugins[$plugin_name] = $plugin_definition;
      }
    }
    return $new_user_plugins;
  }

  /**
   * Get new user plugin option list.
   *
   * @return array
   */
  public function getNewUserPluginOptions() {
    $new_user_plugins = $this
      ->getNewUserPlugins();
    return $this
      ->getPluginsListAsOptions($new_user_plugins);
  }

  /**
   * {@inheritdoc}
   */
  public function getExistingUserPlugins() {
    $existing_user_plugins = array();
    $definitions = $this
      ->getDefinitions();
    foreach ($definitions as $plugin_name => $plugin_definition) {
      if (!empty($plugin_definition['existing_users'])) {
        $existing_user_plugins[$plugin_name] = $plugin_definition;
      }
    }
    return $existing_user_plugins;
  }

  /**
   * Get existing user plugin option list.
   *
   * @return array
   */
  public function getExistingUserPluginOptions() {
    $existing_user_plugins = $this
      ->getExistingUserPlugins();
    return $this
      ->getPluginsListAsOptions($existing_user_plugins);
  }

  /**
   * Get plugin definition list as options usable in Form API.
   *
   * @param array $plugin_definition_list
   *   The plugin definition list to convert.
   *
   * @return array
   *   The plugin options keyed by ID and labeled using label.
   */
  protected function getPluginsListAsOptions(array $plugin_definition_list) {
    $plugin_options = array();
    foreach ($plugin_definition_list as $plugin_definition) {
      $plugin_options[$plugin_definition['id']] = $plugin_definition['label']
        ->render();
    }
    return $plugin_options;
  }

}

Classes

Namesort descending Description
AcceptanceMethodPluginManager Plugin type manager for acceptance methods.