You are here

class VotingApiLoader in Votingapi Widgets 8

Implements lazy loading.

Hierarchy

Expanded class hierarchy of VotingApiLoader

1 string reference to 'VotingApiLoader'
votingapi_widgets.services.yml in ./votingapi_widgets.services.yml
votingapi_widgets.services.yml
1 service uses VotingApiLoader
voting_api.lazy_loader in ./votingapi_widgets.services.yml
Drupal\votingapi_widgets\VotingApiLoader

File

src/VotingApiLoader.php, line 12

Namespace

Drupal\votingapi_widgets
View source
class VotingApiLoader implements TrustedCallbackInterface {

  /**
   * The votingapi_widget widget manager.
   *
   * @var \Drupal\votingapi_widgets\Plugin\VotingApiWidgetManager
   */
  protected $widgetManager;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The VotingApiLoader constructor.
   *
   * @param \Drupal\votingapi_widgets\Plugin\VotingApiWidgetManager $widget_manager
   *   The votingapi_widget widget manager.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(VotingApiWidgetManager $widget_manager, EntityTypeManagerInterface $entity_type_manager) {
    $this->widgetManager = $widget_manager;
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * Build rate form.
   */
  public function buildForm($plugin_id, $entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings) {
    $definitions = $this->widgetManager
      ->getDefinitions();
    $entity = $this->entityTypeManager
      ->getStorage($entity_type)
      ->load($entity_id);
    $plugin = $this->widgetManager
      ->createInstance($plugin_id, $definitions[$plugin_id]);
    $fieldDefinition = $entity->{$field_name}
      ->getFieldDefinition();
    if (empty($plugin) || empty($entity) || !$entity
      ->hasField($field_name)) {
      return [];
    }
    return $plugin
      ->buildForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, unserialize($settings));
  }

  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return [
      'buildForm',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.
VotingApiLoader::$entityTypeManager protected property The entity type manager.
VotingApiLoader::$widgetManager protected property The votingapi_widget widget manager.
VotingApiLoader::buildForm public function Build rate form.
VotingApiLoader::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
VotingApiLoader::__construct public function The VotingApiLoader constructor.