You are here

class FieldResultFunction in Votingapi Widgets 8

Deriver base class for field vote calculations.

Hierarchy

Expanded class hierarchy of FieldResultFunction

File

src/Plugin/Derivative/FieldResultFunction.php, line 13

Namespace

Drupal\votingapi_widgets\Plugin\Derivative
View source
class FieldResultFunction extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The entity field manager service.
   *
   * @var \Drupal\Core\Entity\EntityFieldManagerInterface
   */
  protected $entityFieldManager;

  /**
   * Constructs a FieldResultFunction instance.
   *
   * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
   *   The entity field manager.
   */
  public function __construct(EntityFieldManagerInterface $entity_field_manager) {
    $this->entityFieldManager = $entity_field_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('entity_field.manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $instances = $this->entityFieldManager
      ->getFieldMapByFieldType('voting_api_field');
    $this->derivatives = [];
    foreach ($instances as $entity_type => $fields) {
      foreach (array_keys($fields) as $field_name) {
        $plugin_id = $entity_type . '.' . $field_name;
        $this->derivatives[$plugin_id] = $base_plugin_definition;
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
FieldResultFunction::$entityFieldManager protected property The entity field manager service.
FieldResultFunction::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
FieldResultFunction::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
FieldResultFunction::__construct public function Constructs a FieldResultFunction instance.