Skip to content
Snippets Groups Projects
Commit 5a7585cc authored by Eelke Blok's avatar Eelke Blok
Browse files

Replace directly injected storage

parent 1ea734a3
No related branches found
No related tags found
1 merge request!4Replace directly injected storage
Pipeline #163408 failed
......@@ -21,25 +21,11 @@ use Drupal\Core\File\FileUrlGeneratorInterface;
class VotingApiReactionManager implements ContainerInjectionInterface {
/**
* Vote storage.
* The entity type manager.
*
* @var \Drupal\votingapi\VoteStorage
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $voteStorage;
/**
* Vote type storage.
*
* @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage
*/
protected $voteTypeStorage;
/**
* File storage.
*
* @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage
*/
protected $fileStorage;
protected EntityTypeManagerInterface $entityTypeManager;
/**
* Current user service.
......@@ -110,9 +96,7 @@ class VotingApiReactionManager implements ContainerInjectionInterface {
ExtensionPathResolver $path_resolver,
FileUrlGeneratorInterface $file_url_generator
) {
$this->voteStorage = $entityTypeManager->getStorage('vote');
$this->voteTypeStorage = $entityTypeManager->getStorage('vote_type');
$this->fileStorage = $entityTypeManager->getStorage('file');
$this->entityTypeManager = $entityTypeManager;
$this->currentUser = $currentUser;
$this->votingApiResults = $votingApiResults;
$this->renderer = $renderer;
......@@ -148,7 +132,8 @@ class VotingApiReactionManager implements ContainerInjectionInterface {
* Last reaction for current user.
*/
public function lastReaction(Vote $entity, array $settings) {
$query = $this->voteStorage->getQuery()
$voteStorage = $this->entityTypeManager->getStorage('vote');
$query = $voteStorage->getQuery()
->accessCheck()
->condition('entity_id', $entity->getVotedEntityId())
->condition('entity_type', $entity->getVotedEntityType())
......@@ -187,7 +172,7 @@ class VotingApiReactionManager implements ContainerInjectionInterface {
$ids = $query->execute();
return $this->voteStorage->load(intval(array_pop($ids)));
return $voteStorage->load(intval(array_pop($ids)));
}
/**
......@@ -230,7 +215,8 @@ class VotingApiReactionManager implements ContainerInjectionInterface {
* Active reaction vote types.
*/
public function allReactions() {
return array_filter($this->voteTypeStorage->loadMultiple(), function (VoteType $entity) {
$voteTypeStorage = $this->entityTypeManager->getStorage('vote_type');
return array_filter($voteTypeStorage->loadMultiple(), function (VoteType $entity) {
return $entity->getThirdPartySetting('votingapi_reaction', 'reaction');
});
}
......@@ -355,6 +341,7 @@ class VotingApiReactionManager implements ContainerInjectionInterface {
* Reaction icon url.
*/
public function getIcon(VoteType $entity, &$default = TRUE) {
$fileStorage = $this->entityTypeManager->getStorage('file');
$path = implode('/', [
$this->pathResolver->getPath('module', 'votingapi_reaction'),
'svg',
......@@ -366,7 +353,7 @@ class VotingApiReactionManager implements ContainerInjectionInterface {
$url = $path . 'reaction_noicon.svg';
// User defined icon.
$icon = $entity->getThirdPartySetting('votingapi_reaction', 'icon', '');
if ($file = $this->fileStorage->load($icon)) {
if ($fileStorage->load($icon)) {
/** @var \Drupal\file\FileInterface $file */
$url = $file->getFileUri();
$default = FALSE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment